chore(extractor): add cacheVersion and bump it for HubCloud and HubDrive

This commit is contained in:
WebStreamr 2026-03-17 20:51:57 +00:00
parent 296f0478b0
commit ee3effaf00
No known key found for this signature in database
4 changed files with 19 additions and 3 deletions

View file

@ -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;

View file

@ -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<UrlResult[]>(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}`;
}
}

View file

@ -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/);
}

View file

@ -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) {