peppa/apps/web/app/api/releases/[id]/shots/[n]/route.ts
Асель 6ab17456af PEP-44, PEP-46: review preview with screenshots; Gitea issues, PR comments, manual merge
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 06:06:57 +05:00

19 lines
986 B
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";
export const dynamic = "force-dynamic";
export async function GET(_req: Request, { params }: { params: Promise<{ id: string; n: string }> }) {
const user = await currentUser();
if (!user) return new Response("Нужен вход", { 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("Не найдено", { status: 404 });
return new Response(new Uint8Array(shot.png), { headers: { "Content-Type": "image/png", "Cache-Control": "private, max-age=3600" } });
}