Skip to content

Commit

Permalink
switch from vercel cron to cron-job.org
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdeep-ghosh committed Jul 27, 2024
1 parent 7153431 commit 345c1e3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 39 deletions.
29 changes: 0 additions & 29 deletions src/app/api/delete/route.ts

This file was deleted.

22 changes: 20 additions & 2 deletions src/app/api/drop/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextResponse } from 'next/server';
import { eq } from 'drizzle-orm';
import { eq, lt, sql } from 'drizzle-orm';
import { generateErrorMessage } from 'zod-error';

import { createFileReqSchema, getFileReqSchema } from '@/lib/api/schema/drop';
Expand Down Expand Up @@ -160,4 +160,22 @@ async function GET(req: NextRequest) {
}
}

export { POST, GET };
async function DELETE(req: NextRequest) {
const authHeader = req.headers.get('authorization');
if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
return NextResponse.json('Unauthorized', { status: 401 });
}

try {
await db.delete(filesTable).where(lt(filesTable.expiresAt, sql`now()`));

return NextResponse.json('OK');
} catch (err) {
if (err instanceof Error) {
return NextResponse.json(err.message, { status: 500 });
}
return NextResponse.json('Something went wrong', { status: 500 });
}
}

export { POST, GET, DELETE };
8 changes: 0 additions & 8 deletions vercel.json

This file was deleted.

0 comments on commit 345c1e3

Please sign in to comment.