yt fix #2
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user