feat(history): miniatures des vidéos importées (i.ytimg déterministe)

This commit is contained in:
2026-09-27 12:16:09 -04:00
parent 6c218e8773
commit 201fe979b8
4 changed files with 24 additions and 2 deletions
+6 -1
View File
@@ -893,13 +893,18 @@ r.post('/user/history/takeout', authMiddleware, oauthLimiter, (req, res) => {
const videoId = String(it?.videoId || '').trim().slice(0, 64);
if (!/^[A-Za-z0-9_-]{6,64}$/.test(videoId)) { skipped++; continue; }
const title = String(it?.title || '').slice(0, 300) || videoId;
// Miniature YouTube déterministe quand Takeout n'en fournit pas.
let thumbnail = String(it?.thumbnail || '').slice(0, 500);
if (!thumbnail && /^[A-Za-z0-9_-]{11}$/.test(videoId)) {
thumbnail = `https://i.ytimg.com/vi/${videoId}/hqdefault.jpg`;
}
let watchedAt = new Date().toISOString();
if (it?.watchedAt) {
const d = new Date(String(it.watchedAt));
if (!Number.isNaN(d.getTime())) watchedAt = d.toISOString();
}
try {
upsertWatchHistory({ userId: req.user.id, provider: 'youtube', videoId, title, watchedAt });
upsertWatchHistory({ userId: req.user.id, provider: 'youtube', videoId, title, thumbnail, watchedAt });
imported++;
} catch { skipped++; }
}