show file name in scan log, fix progress total by using Jellyfin page callback
All checks were successful
Build and Push Docker Image / build (push) Successful in 33s
All checks were successful
Build and Push Docker Image / build (push) Successful in 33s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -34,8 +34,8 @@ app.get('/', (c) => {
|
||||
const scanned = (db.prepare("SELECT COUNT(*) as n FROM media_items WHERE scan_status = 'scanned'").get() as { n: number }).n;
|
||||
const errors = (db.prepare("SELECT COUNT(*) as n FROM media_items WHERE scan_status = 'error'").get() as { n: number }).n;
|
||||
const recentItems = db.prepare(
|
||||
'SELECT name, type, scan_status FROM media_items ORDER BY last_scanned_at DESC LIMIT 50'
|
||||
).all() as { name: string; type: string; scan_status: string }[];
|
||||
'SELECT name, type, scan_status, file_path FROM media_items ORDER BY last_scanned_at DESC LIMIT 50'
|
||||
).all() as { name: string; type: string; scan_status: string; file_path: string }[];
|
||||
|
||||
return c.json({ running, progress: { scanned, total, errors }, recentItems, scanLimit: currentScanLimit() });
|
||||
});
|
||||
@@ -134,21 +134,7 @@ async function runScan(limit: number | null = null): Promise<void> {
|
||||
|
||||
let processed = 0;
|
||||
let errors = 0;
|
||||
let total = isDev ? 250 : 0;
|
||||
|
||||
if (!isDev) {
|
||||
try {
|
||||
const countUrl = new URL(`${jellyfinCfg.url}/Users/${jellyfinCfg.userId}/Items`);
|
||||
countUrl.searchParams.set('Recursive', 'true');
|
||||
countUrl.searchParams.set('IncludeItemTypes', 'Movie,Episode');
|
||||
countUrl.searchParams.set('Limit', '1');
|
||||
const countRes = await fetch(countUrl.toString(), { headers: { 'X-Emby-Token': jellyfinCfg.apiKey } });
|
||||
if (countRes.ok) {
|
||||
const body = (await countRes.json()) as { TotalRecordCount: number };
|
||||
total = limit != null ? Math.min(limit, body.TotalRecordCount) : body.TotalRecordCount;
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
let total = 0;
|
||||
|
||||
const upsertItem = db.prepare(`
|
||||
INSERT INTO media_items (
|
||||
@@ -191,7 +177,11 @@ async function runScan(limit: number | null = null): Promise<void> {
|
||||
const getPlanByItemId = db.prepare('SELECT id FROM review_plans WHERE item_id = ?');
|
||||
const getStreamsByItemId = db.prepare('SELECT * FROM media_streams WHERE item_id = ?');
|
||||
|
||||
const itemSource = isDev ? getDevItems(jellyfinCfg) : getAllItems(jellyfinCfg);
|
||||
const itemSource = isDev
|
||||
? getDevItems(jellyfinCfg)
|
||||
: getAllItems(jellyfinCfg, (_fetched, jellyfinTotal) => {
|
||||
total = limit != null ? Math.min(limit, jellyfinTotal) : jellyfinTotal;
|
||||
});
|
||||
for await (const jellyfinItem of itemSource) {
|
||||
if (signal.aborted) break;
|
||||
if (!isDev && limit != null && processed >= limit) break;
|
||||
@@ -248,12 +238,12 @@ async function runScan(limit: number | null = null): Promise<void> {
|
||||
const planRow = getPlanByItemId.get(itemId) as { id: number };
|
||||
for (const dec of analysis.decisions) upsertDecision.run(planRow.id, dec.stream_id, dec.action, dec.target_index);
|
||||
|
||||
emitSse('log', { name: jellyfinItem.Name, type: jellyfinItem.Type, status: 'scanned' });
|
||||
emitSse('log', { name: jellyfinItem.Name, type: jellyfinItem.Type, status: 'scanned', file: jellyfinItem.Path });
|
||||
} catch (err) {
|
||||
errors++;
|
||||
logError(`Error scanning ${jellyfinItem.Name}:`, err);
|
||||
try { db.prepare("UPDATE media_items SET scan_status = 'error', scan_error = ? WHERE jellyfin_id = ?").run(String(err), jellyfinItem.Id); } catch { /* ignore */ }
|
||||
emitSse('log', { name: jellyfinItem.Name, type: jellyfinItem.Type, status: 'error' });
|
||||
emitSse('log', { name: jellyfinItem.Name, type: jellyfinItem.Type, status: 'error', file: jellyfinItem.Path });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user