mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-20 16:22:04 +00:00
fix logic for cdn caching
This commit is contained in:
parent
94fc9b639f
commit
ec9c0db867
1 changed files with 18 additions and 2 deletions
|
|
@ -14,8 +14,8 @@ interface CacheEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TrailerService {
|
export class TrailerService {
|
||||||
// YouTube CDN URLs expire ~6h; cache for 5h
|
// Cache for 3 minutes — just enough to avoid re-extracting on quick re-renders
|
||||||
private static readonly CACHE_TTL_MS = 5 * 60 * 60 * 1000;
|
private static readonly CACHE_TTL_MS = 3 * 60 * 1000;
|
||||||
private static urlCache = new Map<string, CacheEntry>();
|
private static urlCache = new Map<string, CacheEntry>();
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
@ -137,6 +137,22 @@ export class TrailerService {
|
||||||
this.urlCache.delete(key);
|
this.urlCache.delete(key);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
// Check the URL's own CDN expiry — googlevideo.com URLs carry an `expire`
|
||||||
|
// param (Unix timestamp). Treat as stale if it expires within 2 minutes.
|
||||||
|
if (entry.url.includes('googlevideo.com')) {
|
||||||
|
try {
|
||||||
|
const u = new URL(entry.url);
|
||||||
|
const expire = u.searchParams.get('expire');
|
||||||
|
if (expire) {
|
||||||
|
const expiresAt = parseInt(expire, 10) * 1000;
|
||||||
|
if (Date.now() > expiresAt - 2 * 60 * 1000) {
|
||||||
|
logger.info('TrailerService', `Cached URL expired or expiring soon — re-extracting`);
|
||||||
|
this.urlCache.delete(key);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch { /* ignore */ }
|
||||||
|
}
|
||||||
return entry.url;
|
return entry.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue