mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-03-11 09:35:42 +00:00
Merge pull request #601 from chrisk325/patch-13
fix logic for cdn caching
This commit is contained in:
commit
642f4ce7aa
1 changed files with 18 additions and 2 deletions
|
|
@ -14,8 +14,8 @@ interface CacheEntry {
|
|||
}
|
||||
|
||||
export class TrailerService {
|
||||
// YouTube CDN URLs expire ~6h; cache for 5h
|
||||
private static readonly CACHE_TTL_MS = 5 * 60 * 60 * 1000;
|
||||
// Cache for 3 minutes — just enough to avoid re-extracting on quick re-renders
|
||||
private static readonly CACHE_TTL_MS = 3 * 60 * 1000;
|
||||
private static urlCache = new Map<string, CacheEntry>();
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -137,6 +137,22 @@ export class TrailerService {
|
|||
this.urlCache.delete(key);
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue