import { projectRef } from "@/lib/projects";
import { kindMakesTakes } from "@/lib/projects/kinds.mjs";
import { projectShareLine } from "@/lib/report/shareLine.mjs";
export const dynamic = "force-dynamic";
// A CLIP'S SHARE LINE (lane output-modes): what the take panel's and Play's
// **Copy share line** copy -- the platform's page at the first second the clip
// plays and its moment on the archive (lib/report/shareLine.mjs; a Rumble
// folder id as the embed id the archive serves). `umtool share
[]
// [--take ]` is its twin.
//
// GET ?project=[&clip=][&take=] -> { clip, seconds, platform, archive, text }
const headers = { "cache-control": "no-store" };
const ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
export async function GET(request: Request) {
const url = new URL(request.url);
const project = await projectRef(url.searchParams.get("project") ?? "");
if (!project) return Response.json({ error: "no such project" }, { status: 404, headers });
if (!kindMakesTakes(project.kind)) return Response.json({ error: "a share line is a report video's clip's" }, { status: 400, headers });
const clip = url.searchParams.get("clip") || null;
const take = url.searchParams.get("take") || null;
if ((clip && !ID_RE.test(clip)) || (take && !ID_RE.test(take))) return Response.json({ error: "clip and take are ids" }, { status: 400, headers });
try {
const line = await projectShareLine(project, { clip, take });
return Response.json(line, { headers });
} catch (e) {
return Response.json({ error: e instanceof Error ? e.message : String(e) }, { status: 404, headers });
}
}