Shows a "Replay" button on non-active jobs that re-creates a new job of the same type and library. Supports all replayable job types: rebuild, full_rebuild, rescan, scan, thumbnail_rebuild, thumbnail_regenerate, metadata_batch, metadata_refresh. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.7 KiB
TypeScript
39 lines
1.7 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { apiFetch, IndexJobDto, rebuildIndex, rebuildThumbnails, regenerateThumbnails, startMetadataBatch, startMetadataRefresh } 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));
|
|
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 });
|
|
}
|
|
}
|