From fe3af86c87f7ed61732bb803ffc486a10e4ac503 Mon Sep 17 00:00:00 2001 From: Kibi Kelburton Date: Wed, 3 Jun 2026 13:43:26 +0200 Subject: [PATCH] yt fix #2 --- src/inc/routeinc/f0cklib.mjs | 9 ++++++++- src/inc/routes/apiv2/index.mjs | 10 ++++++++-- src/inc/routes/scroller.mjs | 13 ++++++++++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/inc/routeinc/f0cklib.mjs b/src/inc/routeinc/f0cklib.mjs index c789400..f42a93e 100644 --- a/src/inc/routeinc/f0cklib.mjs +++ b/src/inc/routeinc/f0cklib.mjs @@ -797,7 +797,14 @@ export default { return `${ratingLabel}${titlePart} · uploaded by ${actitem.username}`; })(), coverart: coverartUrl, - dest: actitem.mime === 'video/youtube' ? actitem.dest : `${cfg.websrv.paths.images}/${actitem.dest}`, + dest: (() => { + if (actitem.mime !== 'video/youtube') return `${cfg.websrv.paths.images}/${actitem.dest}`; + if (actitem.dest && actitem.dest.startsWith('yt:')) return actitem.dest; + // dest was corrupted by UUID backfill — recover from src + const ytSrcRegex = /(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\/?\?(?:\S*?&?v=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/i; + const m = actitem.src && actitem.src.match(ytSrcRegex); + return m ? `yt:${m[1]}` : actitem.dest; + })(), mime: actitem.mime, size: lib.formatSize(actitem.size), checksum: actitem.checksum, diff --git a/src/inc/routes/apiv2/index.mjs b/src/inc/routes/apiv2/index.mjs index cf175b3..0d64ed6 100644 --- a/src/inc/routes/apiv2/index.mjs +++ b/src/inc/routes/apiv2/index.mjs @@ -538,8 +538,14 @@ export default router => { } const isYouTube = item.mime === 'video/youtube'; - const relativeDest = isYouTube ? item.dest : `${cfg.websrv.paths.images}/${item.dest}`; - const directUrl = isYouTube ? item.dest : `${cfg.main.url.full}${cfg.websrv.paths.images}/${item.dest}`; + const ytSrcRegex = /(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\/?\?(?:\S*?&?v=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/i; + let ytDest = item.dest; + if (isYouTube && (!ytDest || !ytDest.startsWith('yt:'))) { + const m = item.src && item.src.match(ytSrcRegex); + if (m) ytDest = `yt:${m[1]}`; + } + const relativeDest = isYouTube ? ytDest : `${cfg.websrv.paths.images}/${item.dest}`; + const directUrl = isYouTube ? ytDest : `${cfg.main.url.full}${cfg.websrv.paths.images}/${item.dest}`; const { username, src, xd_score, ...safeItem } = item; diff --git a/src/inc/routes/scroller.mjs b/src/inc/routes/scroller.mjs index f6165c8..7c173eb 100644 --- a/src/inc/routes/scroller.mjs +++ b/src/inc/routes/scroller.mjs @@ -298,6 +298,8 @@ export default (router, tpl) => { `; } + const ytSrcRegex = /(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\/?\/?\?(?:\S*?&?v=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11})/i; + const items = rows.map(row => { const isVideo = row.mime && row.mime.startsWith('video') && row.mime !== 'video/youtube'; const isYouTube = row.mime === 'video/youtube'; @@ -305,7 +307,16 @@ export default (router, tpl) => { const isImage = row.mime && row.mime.startsWith('image'); let dest = row.dest; - if (!isYouTube && dest) dest = `${cfg.websrv.paths.images}/${row.dest}`; + if (isYouTube) { + // Guard against dest values corrupted by the UUID backfill script: + // dest should be "yt:VIDEO_ID" — if it isn't, recover the ID from src. + if (!dest || !dest.startsWith('yt:')) { + const m = row.src && row.src.match(ytSrcRegex); + if (m) dest = `yt:${m[1]}`; + } + } else if (dest) { + dest = `${cfg.websrv.paths.images}/${row.dest}`; + } const thumbnail = `${cfg.websrv.paths.thumbnails}/${row.id}.webp`; let ratingLabel = '?'; let ratingClass = 'untagged';