Files
stripstream-librarian/apps/backoffice/app/api/jobs/[id]/replay/route.ts
Froidefond Julien 5f7f96f25a
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 51s
chore: bump version to 2.3.0
2026-03-25 08:15:04 +01:00

42 lines
2.0 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { apiFetch, IndexJobDto, rebuildIndex, rebuildThumbnails, regenerateThumbnails, startMetadataBatch, startMetadataRefresh, startReadingStatusMatch } from "@/lib/api";
export async function POST(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
try {
const job = await apiFetch<IndexJobDto>(`/index/jobs/${id}`);
const libraryId = job.library_id ?? undefined;
switch (job.type) {
case "rebuild":
return NextResponse.json(await rebuildIndex(libraryId));
case "full_rebuild":
return NextResponse.json(await rebuildIndex(libraryId, true));
case "rescan":
return NextResponse.json(await rebuildIndex(libraryId, false, true));
case "scan":
return NextResponse.json(await rebuildIndex(libraryId));
case "thumbnail_rebuild":
return NextResponse.json(await rebuildThumbnails(libraryId));
case "thumbnail_regenerate":
return NextResponse.json(await regenerateThumbnails(libraryId));
case "metadata_batch":
if (!libraryId) return NextResponse.json({ error: "Library ID required for metadata batch" }, { status: 400 });
return NextResponse.json(await startMetadataBatch(libraryId));
case "metadata_refresh":
if (!libraryId) return NextResponse.json({ error: "Library ID required for metadata refresh" }, { status: 400 });
return NextResponse.json(await startMetadataRefresh(libraryId));
case "reading_status_match":
if (!libraryId) return NextResponse.json({ error: "Library ID required for reading status match" }, { status: 400 });
return NextResponse.json(await startReadingStatusMatch(libraryId));
default:
return NextResponse.json({ error: `Cannot replay job type: ${job.type}` }, { status: 400 });
}
} catch (error) {
return NextResponse.json({ error: "Failed to replay job" }, { status: 500 });
}
}