fix: xREL Endpoint nutzt media_type im Cache-Key, TV-Jahresfilter deaktiviert
This commit is contained in:
@@ -427,11 +427,10 @@ router.get('/movie/:id', authenticate, async (req, res) => {
|
|||||||
// xREL on-demand – ?refresh=1 ignoriert Cache, ?imdb_id=tt...&title=...&orig=... vermeidet TMDb-Calls
|
// xREL on-demand – ?refresh=1 ignoriert Cache, ?imdb_id=tt...&title=...&orig=... vermeidet TMDb-Calls
|
||||||
router.get('/movie/:id/xrel', authenticate, async (req, res) => {
|
router.get('/movie/:id/xrel', authenticate, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const cacheKey = `xrel:tmdb:${req.params.id}`;
|
const xrelMediaType = req.query.media_type || 'movie';
|
||||||
|
const cacheKey = `xrel:${xrelMediaType}:${req.params.id}`;
|
||||||
const forceRefresh = req.query.refresh === '1';
|
const forceRefresh = req.query.refresh === '1';
|
||||||
|
|
||||||
// Cache prüfen: befüllte Einträge immer zurückgeben
|
|
||||||
// Bei refresh=1 oder leerem Cache: xREL aufrufen
|
|
||||||
if (!forceRefresh) {
|
if (!forceRefresh) {
|
||||||
const cached = cacheGet(cacheKey);
|
const cached = cacheGet(cacheKey);
|
||||||
if (cached !== undefined) {
|
if (cached !== undefined) {
|
||||||
@@ -442,32 +441,31 @@ router.get('/movie/:id/xrel', authenticate, async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Cache löschen bei refresh (damit neu gecacht wird)
|
|
||||||
if (forceRefresh) {
|
if (forceRefresh) {
|
||||||
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey);
|
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey);
|
||||||
|
// Auch alten Key löschen
|
||||||
|
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(`xrel:tmdb:${req.params.id}`);
|
||||||
}
|
}
|
||||||
// Immer xREL aufrufen wenn kein befüllter Cache
|
|
||||||
|
|
||||||
// Titel + IMDb-ID aus Query-Params wenn vorhanden (spart 2 TMDb-Calls)
|
|
||||||
let imdbId = req.query.imdb_id || null;
|
let imdbId = req.query.imdb_id || null;
|
||||||
let title = req.query.title || null;
|
let title = req.query.title || null;
|
||||||
let origTitle = req.query.orig || null;
|
let origTitle = req.query.orig || null;
|
||||||
|
|
||||||
if (!title) {
|
if (!title) {
|
||||||
|
const endpoint = xrelMediaType === 'tv' ? 'tv' : 'movie';
|
||||||
const [detail, extIds] = await Promise.all([
|
const [detail, extIds] = await Promise.all([
|
||||||
tmdb(`/movie/${req.params.id}`, { append_to_response: '' }).catch(()=>({})),
|
tmdb(`/${endpoint}/${req.params.id}`, { append_to_response: '' }).catch(()=>({})),
|
||||||
tmdb(`/movie/${req.params.id}/external_ids`).catch(()=>({})),
|
tmdb(`/${endpoint}/${req.params.id}/external_ids`).catch(()=>({})),
|
||||||
]);
|
]);
|
||||||
imdbId = extIds.imdb_id || null;
|
imdbId = extIds.imdb_id || null;
|
||||||
title = detail.title || null;
|
title = detail.name || detail.title || null;
|
||||||
origTitle = detail.original_title || null;
|
origTitle = detail.original_name || detail.original_title || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filmjahr aus Query-Param; year=0 oder fehlt → kein Jahresfilter
|
|
||||||
let filmYear = null;
|
let filmYear = null;
|
||||||
if (req.query.year && req.query.year !== '0') filmYear = parseInt(req.query.year);
|
if (req.query.year && req.query.year !== '0' && xrelMediaType !== 'tv') filmYear = parseInt(req.query.year);
|
||||||
const data = await getXrelData(req.params.id, imdbId, title, origTitle, filmYear, media_type);
|
const data = await getXrelData(req.params.id, imdbId, title, origTitle, filmYear, xrelMediaType);
|
||||||
const releases = Array.isArray(data) ? data : (data.releases || []);
|
const releases = Array.isArray(data) ? data : (data.releases || []);
|
||||||
const xrel_dates = Array.isArray(data) ? [] : (data.xrel_dates || []);
|
const xrel_dates = Array.isArray(data) ? [] : (data.xrel_dates || []);
|
||||||
res.json({ xrel: releases, xrel_dates, has_xrel: releases.length > 0 });
|
res.json({ xrel: releases, xrel_dates, has_xrel: releases.length > 0 });
|
||||||
} catch(e) { res.status(500).json({ error: e.message }); }
|
} catch(e) { res.status(500).json({ error: e.message }); }
|
||||||
@@ -481,7 +479,7 @@ router.get('/xrel-cached', authenticate, (req, res) => {
|
|||||||
if (!ids.length) return res.json({});
|
if (!ids.length) return res.json({});
|
||||||
const result = {};
|
const result = {};
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const cached = cacheGet(`xrel:tmdb:${id}`);
|
const cached = cacheGet(`xrel:movie:${id}`) || cacheGet(`xrel:tv:${id}`) || cacheGet(`xrel:tmdb:${id}`);
|
||||||
result[id] = cached !== undefined && (Array.isArray(cached) ? cached.length > 0 : cached.releases?.length > 0);
|
result[id] = cached !== undefined && (Array.isArray(cached) ? cached.length > 0 : cached.releases?.length > 0);
|
||||||
}
|
}
|
||||||
res.json(result);
|
res.json(result);
|
||||||
|
|||||||
Reference in New Issue
Block a user