21 lines
1.0 KiB
TypeScript
21 lines
1.0 KiB
TypeScript
// Screenshots of a preview stand (PEP-44), taken by the project's CI step: only the
|
||
// project's owner and members see them.
|
||
import { projectForUser } from "@peppa/core";
|
||
import { releaseScreenshot } from "@peppa/runner";
|
||
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 = await releaseScreenshot(db, Number(id), Number(n));
|
||
const allowed = shot && (await projectForUser(db, user.id, shot.projectId).then(() => true, () => false));
|
||
if (!shot || !allowed) return new Response(t("Не найдено"), { status: 404 });
|
||
return new Response(new Uint8Array(shot.png), { headers: { "Content-Type": "image/png", "Cache-Control": "private, max-age=3600" } });
|
||
}
|