enrich GET /api/review/:id with the latest job row

This commit is contained in:
2026-04-15 07:00:47 +02:00
parent 0d6781973b
commit 688443e732

View File

@@ -4,7 +4,7 @@ import { isOneOf, parseId } from "../lib/validate";
import { analyzeItem, assignTargetOrder } from "../services/analyzer";
import { buildCommand } from "../services/ffmpeg";
import { getItem, mapStream, normalizeLanguage, refreshItem } from "../services/jellyfin";
import type { MediaItem, MediaStream, ReviewPlan, StreamDecision } from "../types";
import type { Job, MediaItem, MediaStream, ReviewPlan, StreamDecision } from "../types";
const app = new Hono();
@@ -110,7 +110,7 @@ function rowToPlan(r: RawRow): ReviewPlan | null {
function loadItemDetail(db: ReturnType<typeof getDb>, itemId: number) {
const item = db.prepare("SELECT * FROM media_items WHERE id = ?").get(itemId) as MediaItem | undefined;
if (!item) return { item: null, streams: [], plan: null, decisions: [], command: null };
if (!item) return { item: null, streams: [], plan: null, decisions: [], command: null, job: null };
const streams = db
.prepare("SELECT * FROM media_streams WHERE item_id = ? ORDER BY stream_index")
@@ -122,7 +122,15 @@ function loadItemDetail(db: ReturnType<typeof getDb>, itemId: number) {
const command = plan && !plan.is_noop ? buildCommand(item, streams, decisions) : null;
return { item, streams, plan: plan ?? null, decisions, command };
const job = db
.prepare(
`SELECT id, item_id, command, job_type, status, output, exit_code,
created_at, started_at, completed_at
FROM jobs WHERE item_id = ? ORDER BY created_at DESC LIMIT 1`,
)
.get(itemId) as Job | undefined;
return { item, streams, plan: plan ?? null, decisions, command, job: job ?? null };
}
/**