fix: Badges + Releases persistent nach Reload via Cache-Check ohne xREL-Call

This commit is contained in:
2026-06-11 02:13:26 +02:00
parent 9076fbcc0b
commit 7ff6ce6da2
2 changed files with 36 additions and 3 deletions

View File

@@ -283,6 +283,18 @@ router.get('/movie/:id/xrel', authenticate, async (req, res) => {
// GET /api/tools/media/xrel-cached?ids=1,2,3 welche Filme haben Releases im Cache
router.get('/xrel-cached', authenticate, (req, res) => {
const ids = (req.query.ids || '').split(',').map(Number).filter(Boolean);
if (!ids.length) return res.json({});
const result = {};
for (const id of ids) {
const cached = cacheGet(`xrel:tmdb:${id}`);
result[id] = cached !== undefined && cached.length > 0;
}
res.json(result);
});
router.get('/favorites', authenticate, (req, res) => {
res.json(db.prepare('SELECT * FROM movie_favorites WHERE user_id=? ORDER BY release_date ASC').all(req.user.id));
});

View File

@@ -262,11 +262,20 @@ function KinoGrid({ onOpenModal, xrelIds }) {
const [error, setError] = useState('');
const [favIds, toggleFav] = useFavIds();
// Filme laden
// Filme laden + Cache-Status für Badges
useEffect(() => {
setLoading(true); setError('');
api('/tools/media/now-playing')
.then(setMovies)
.then(list => {
setMovies(list);
// Badges aus Cache laden (kein xREL-Call, nur DB)
const ids = list.map(m => m.id).join(',');
if (ids) api(`/tools/media/xrel-cached?ids=${ids}`)
.then(result => {
const hits = Object.entries(result).filter(([,v])=>v).map(([k])=>Number(k));
if (hits.length) setXrelIds(prev => new Set([...prev, ...hits]));
}).catch(()=>{});
})
.catch(e => setError(e.message))
.finally(() => setLoading(false));
}, []);
@@ -316,7 +325,15 @@ function DemnächstGrid({ onOpenModal, xrelIds }) {
useEffect(() => {
setLoading(true); setError('');
api('/tools/media/upcoming')
.then(setGroups)
.then(grps => {
setGroups(grps);
const ids = Object.values(grps).flat().map(m => m.id).join(',');
if (ids) api(`/tools/media/xrel-cached?ids=${ids}`)
.then(result => {
const hits = Object.entries(result).filter(([,v])=>v).map(([k])=>Number(k));
if (hits.length) setXrelIds(prev => new Set([...prev, ...hits]));
}).catch(()=>{});
})
.catch(e => setError(e.message))
.finally(() => setLoading(false));
}, []);
@@ -450,6 +467,10 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
api(`/tools/media/movie/${tmdbId}`)
.then(d => { setDetail(d); setLoading(false); })
.catch(e => { setError(e.message); setLoading(false); });
// Cached Releases sofort laden falls vorhanden
api(`/tools/media/movie/${tmdbId}/xrel`)
.then(d => { if (d.xrel?.length) { setXrel(d.xrel); onHasXrel?.(tmdbId); } })
.catch(()=>{});
const prev = document.body.style.overflow;
document.body.style.overflow = 'hidden';
return () => { document.body.style.overflow = prev; };