feat: Media Streaming - Admin Cache-Clear Button pro Anbieter

This commit is contained in:
2026-07-04 14:03:24 +02:00
parent e774dd3ac5
commit 98265883ac
2 changed files with 44 additions and 1 deletions

View File

@@ -34,6 +34,9 @@ function cacheSet(key, value, ttlMs = 12 * 60 * 60 * 1000) {
db.prepare('INSERT OR REPLACE INTO xrel_cache (cache_key,value,expires_at) VALUES (?,?,?)')
.run(key, JSON.stringify(value), Date.now() + ttlMs);
}
function cacheDelete(key) {
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(key);
}
// ── TMDb ──────────────────────────────────────────────────────────────────────
function getToken() {
@@ -666,6 +669,15 @@ router.get('/streaming/:providerId/new', authenticate, async (req, res) => {
} catch(e) { res.status(500).json({ error: e.message }); }
});
// ── Cache leeren für einen Provider (Admin) ──────────────────────────────────
router.post('/streaming/:providerId/clear-cache', authenticate, requireAdmin, (req, res) => {
const provider = STREAMING_PROVIDERS.find(p => p.id === req.params.providerId);
if (!provider) return res.status(404).json({ error: 'Unbekannter Anbieter' });
cacheDelete(`streaming-top10:${provider.id}`);
cacheDelete(`streaming-new:${provider.id}`);
res.json({ ok: true, provider: provider.id });
});
router.get('/streaming/:providerId', authenticate, async (req, res) => {
try {
const provider = STREAMING_PROVIDERS.find(p => p.id === req.params.providerId);
@@ -678,7 +690,7 @@ router.get('/streaming/:providerId', authenticate, async (req, res) => {
// Nur Titel der letzten 2 Jahre (aktuelles Jahr - 1)
// Für kleine Kataloge (HBO Max, WOW, RTL+) kein Jahresfilter — TMDb hat dort
// zu wenige Titel mit korrekt erfasstem DE-Datum seit letztem Jahr
const SMALL_CATALOGS = new Set(['max', 'wow', 'rtlplus']);
const SMALL_CATALOGS = new Set(['max']);
const minYear = new Date().getFullYear() - 1;
const minDate = SMALL_CATALOGS.has(provider.id) ? null : `${minYear}-01-01`;