Import source: vault/app/raw/[id]/route
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -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",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user