src/app/api/inbox/seen/route.ts
Linked repository file from this build.
import { NextResponse } from "next/server";
import { z } from "zod";
import { apiRoute } from "@/lib/api-route";
import { getActor } from "@/lib/auth/server";
import { inboxSeen } from "@/lib/db/inbox-store";
const schema = z.object({
asOf: z
.string()
.refine((at) => Number.isFinite(Date.parse(at)) && Date.parse(at) <= Date.now())
.optional(),
});
export const POST = apiRoute("Unable to save your inbox visit.", async (request) => {
const actor = await getActor(request);
const body = schema.safeParse(await request.json().catch(() => ({})));
if (!body.success)
return NextResponse.json({ error: "Invalid inbox visit date." }, { status: 400 });
const at = body.data.asOf;
await inboxSeen(actor, at ? new Date(at).toISOString() : undefined);
return NextResponse.json({ ok: true });
});