Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat(web): add agent API cleanup cron job

Richie McIlroy8e78533a8c71
diff --git a/apps/web/app/api/cron/cleanup-agent-api/route.ts b/apps/web/app/api/cron/cleanup-agent-api/route.ts
new file mode 100644
index 000000000..8b264b619
--- /dev/null
+++ b/apps/web/app/api/cron/cleanup-agent-api/route.ts
@@ -0,0 +1,28 @@
+import { timingSafeEqual } from "node:crypto";
+import { NextResponse } from "next/server";
+import { cleanupExpiredAgentApiRecords } from "@/lib/agent-api-cleanup";
+
+export const dynamic = "force-dynamic";
+
+export async function GET(request: Request) {
+ const cronSecret = process.env.CRON_SECRET;
+ if (!cronSecret) {
+ return NextResponse.json(
+ { error: "Server misconfiguration" },
+ { status: 500 },
+ );
+ }
+
+ const authorization = request.headers.get("authorization");
+ const expected = `Bearer ${cronSecret}`;
+ if (
+ !authorization ||
+ authorization.length !== expected.length ||
+ !timingSafeEqual(Buffer.from(authorization), Buffer.from(expected))
+ ) {
+ return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
+ }
+
+ const deleted = await cleanupExpiredAgentApiRecords();
+ return NextResponse.json({ success: true, deleted });
+}
diff --git a/apps/web/vercel.json b/apps/web/vercel.json
index c1ae294c4..0b0ba9f67 100644
--- a/apps/web/vercel.json
+++ b/apps/web/vercel.json
@@ -1,6 +1,10 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"crons": [
+ {
+ "path": "/api/cron/cleanup-agent-api",
+ "schedule": "17 3 * * *"
+ },
{
"path": "/api/cron/finalize-stale-desktop-segments",
"schedule": "*/15 * * * *"