Refetch missing media from catalog source

This commit is contained in:
Jonathan Sykes
2026-10-14 01:26:25 +08:00
parent 593ecaecd9
commit ca10fe6486
6 changed files with 46 additions and 12 deletions

View File

@@ -314,6 +314,7 @@ export function verifyAdminCookie(secret, value, nowSec = Math.floor(Date.now()
export function registerNoteRoutes(app, deps) {
const {
db, getProfile, profileNameRe, runYtdlp, adminPassword, backupDir, adminHtmlPath, workerToken,
catalog = null, media = null,
} = deps;
const ADMIN_COOKIE = 'ytp_admin';
const ADMIN_TTL = 30 * 24 * 3600;
@@ -695,6 +696,7 @@ export function registerNoteRoutes(app, deps) {
const n = await db.getNotes(r.video_id);
out.push({
id: r.video_id, cacheStatus: r.status, title: meta.title || '', channel: meta.channel || meta.uploader || '',
sourceUrl: catalog ? await catalog.getSourceUrl(r.video_id) : null,
duration: Number(r.duration) || 0, lastAccess: Number(r.last_access) || 0,
lyricsRev: n.lyrics ? n.lyrics.rev : 0, lyricsLines: n.lyrics ? n.lyrics.data.lines.length : 0,
});
@@ -703,6 +705,12 @@ export function registerNoteRoutes(app, deps) {
return c.json({ ok: true, media: out });
});
app.post('/api/admin/media/:id/redownload', requireAdminOrToken, async c => {
if (!media) return c.json({ ok: false, error: 'media cache unavailable' }, 503);
try { return c.json({ ok: true, ...(await media.redownload(c.req.param('id'))) }, 202); }
catch (err) { return c.json({ ok: false, error: err.message }, 400); }
});
app.get('/api/admin/notes/recent', requireAdmin, async (c) => c.json({ ok: true, revs: await db.recentNoteRevs(150) }));
app.post('/api/admin/notes/:id/:kind/restore', requireAdmin, async (c) => {