chore(extractor): add cacheVersion and bump it for HubCloud and HubDrive
This commit is contained in:
parent
296f0478b0
commit
ee3effaf00
4 changed files with 19 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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}`;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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/);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue