Import source: vault/app/api/share/[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:
arsam
2026-09-18 23:16:53 +03:30
parent 9f961fc4aa
commit 26de528a96
+27
View File
@@ -0,0 +1,27 @@
import { NextResponse } from "next/server";
import { jsonError, purgeExpiredSnippets, publicSnippet } 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((candidate) => candidate.id === id);
if (!snippet) return jsonError("Snippet not found", 404);
if (snippet.privacy === "password") {
return NextResponse.json({
locked: true,
snippet: {
...publicSnippet(snippet),
code: "",
},
});
}
return NextResponse.json({ locked: false, snippet: publicSnippet(snippet) });
}