diff --git a/src/extractor/Extractor.ts b/src/extractor/Extractor.ts index 84f111c..e33c33f 100644 --- a/src/extractor/Extractor.ts +++ b/src/extractor/Extractor.ts @@ -9,6 +9,8 @@ export abstract class Extractor { public readonly ttl: number = 900000; // 15m + public readonly cacheVersion: number | undefined = undefined; + public readonly viaMediaFlowProxy: boolean = false; protected readonly fetcher: Fetcher; diff --git a/src/extractor/ExtractorRegistry.ts b/src/extractor/ExtractorRegistry.ts index f273576..d04677f 100644 --- a/src/extractor/ExtractorRegistry.ts +++ b/src/extractor/ExtractorRegistry.ts @@ -44,9 +44,7 @@ export class ExtractorRegistry { } const normalizedUrl = extractor.normalize(url); - const cacheKey = extractor.viaMediaFlowProxy - ? `${extractor.id}_${normalizedUrl}_${ctx.config.mediaFlowProxyUrl}` - : `${extractor.id}_${normalizedUrl}`; + const cacheKey = this.determineCacheKey(ctx, extractor, normalizedUrl); const storedDataRaw = await this.urlResultCache.getRaw(cacheKey); const expires = storedDataRaw?.expires; @@ -99,4 +97,16 @@ export class ExtractorRegistry { return urlResults; }; + + private determineCacheKey(ctx: Context, extractor: Extractor, url: URL): string { + let suffix = ''; + if (extractor.viaMediaFlowProxy) { + suffix += `_${ctx.config.mediaFlowProxyUrl}`; + } + if (extractor.cacheVersion) { + suffix += `_${extractor.cacheVersion}`; + } + + return `${extractor.id}_${url}${suffix}`; + } } diff --git a/src/extractor/HubCloud.ts b/src/extractor/HubCloud.ts index b46f8e1..9d90dff 100644 --- a/src/extractor/HubCloud.ts +++ b/src/extractor/HubCloud.ts @@ -10,6 +10,8 @@ export class HubCloud extends Extractor { public override readonly ttl: number = 43200000; // 12h + public override readonly cacheVersion = 1; + public supports(_ctx: Context, url: URL): boolean { return null !== url.host.match(/hubcloud/); } diff --git a/src/extractor/HubDrive.ts b/src/extractor/HubDrive.ts index 6d8aec2..c4f2480 100644 --- a/src/extractor/HubDrive.ts +++ b/src/extractor/HubDrive.ts @@ -11,6 +11,8 @@ export class HubDrive extends Extractor { public override readonly ttl: number = 43200000; // 12h + public override readonly cacheVersion = 1; + private readonly hubCloud: HubCloud; public constructor(fetcher: Fetcher, hubCloud: HubCloud) {