diff --git a/vault/app/raw/[id]/route.ts b/vault/app/raw/[id]/route.ts new file mode 100644 index 0000000..8da5c8f --- /dev/null +++ b/vault/app/raw/[id]/route.ts @@ -0,0 +1,34 @@ +import { purgeExpiredSnippets } from "@/lib/server-api"; +import { readDb } from "@/lib/server-db"; + +interface RouteContext { + params: Promise<{ id: string }>; +} + +export async function GET(_request: Request, context: RouteContext) { + await purgeExpiredSnippets(); + const { id } = await context.params; + const db = await readDb(); + const snippet = db.snippets.find((s) => s.id === id); + + if (!snippet) { + return new Response("404 Not Found\n", { + status: 404, + headers: { "Content-Type": "text/plain; charset=utf-8" }, + }); + } + + if (snippet.privacy === "password") { + return new Response("403 Forbidden: This snippet is password-protected.\n", { + status: 403, + headers: { "Content-Type": "text/plain; charset=utf-8" }, + }); + } + + return new Response(snippet.code, { + headers: { + "Content-Type": "text/plain; charset=utf-8", + "Cache-Control": "no-store", + }, + }); +}