peppa/apps/web/app/api/releases/[id]/shots/[n]/route.ts
2026-11-15 14:47:50 +05:00

21 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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" } });
}