21 lines
1.1 KiB
TypeScript
21 lines
1.1 KiB
TypeScript
// PEP-143: a screenshot of a report — only its author and the superadmins see it.
|
||
import { feedbackScreenshot } from "@peppa/core";
|
||
import { currentUser } from "@/lib/auth";
|
||
import { db } from "@/lib/db";
|
||
import { getT } from "@/lib/i18n";
|
||
|
||
export const dynamic = "force-dynamic";
|
||
|
||
export async function GET(_req: Request, { params }: { params: Promise<{ id: string; n: string }> }) {
|
||
const user = await currentUser();
|
||
const t = await getT();
|
||
if (!user) return new Response(t("Нужен вход"), { status: 401 });
|
||
const { id, n } = await params;
|
||
const shot = /^\d+$/.test(id) && /^\d+$/.test(n) ? await feedbackScreenshot(db, user, Number(id), Number(n)) : null;
|
||
// Somebody else's report and a missing one look the same.
|
||
if (!shot) return new Response(t("Не найдено"), { status: 404 });
|
||
return new Response(new Uint8Array(shot.data), {
|
||
headers: { "Content-Type": shot.mime, "Cache-Control": "private, max-age=3600", "X-Content-Type-Options": "nosniff", "Content-Disposition": "inline", "Content-Security-Policy": "default-src 'none'; sandbox" },
|
||
});
|
||
}
|