Skip to content

Commit ff8edcc

Browse files
committed
fix(presets/mediafusion): override cache key via wrapper APi
1 parent 44463c3 commit ff8edcc

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

packages/core/src/main/wrapper.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export class Wrapper {
185185
resource: 'manifest',
186186
type: 'manifest',
187187
id: 'manifest',
188+
headers: this.addon.headers,
188189
options: this.addon.preset.options,
189190
}) || this.manifestUrl;
190191

@@ -262,6 +263,7 @@ export class Wrapper {
262263
type,
263264
id,
264265
options: this.addon.preset.options,
266+
headers: this.addon.headers,
265267
}) || this.buildResourceUrl('stream', type, id);
266268
const streamTtl = resolveTtl(
267269
appConfig.resources.cache.stream.ttl,
@@ -279,6 +281,7 @@ export class Wrapper {
279281
resource: 'stream',
280282
type,
281283
id,
284+
headers: this.addon.headers,
282285
options: this.addon.preset.options,
283286
})
284287
);
@@ -348,6 +351,7 @@ export class Wrapper {
348351
type,
349352
id,
350353
options: this.addon.preset.options,
354+
headers: this.addon.headers,
351355
extras,
352356
})
353357
);
@@ -386,6 +390,7 @@ export class Wrapper {
386390
resource: 'meta',
387391
type,
388392
id,
393+
headers: this.addon.headers,
389394
options: this.addon.preset.options,
390395
})
391396
);
@@ -430,6 +435,7 @@ export class Wrapper {
430435
resource: 'subtitles',
431436
type,
432437
id,
438+
headers: this.addon.headers,
433439
options: this.addon.preset.options,
434440
})
435441
);
@@ -461,6 +467,7 @@ export class Wrapper {
461467
type,
462468
id,
463469
options: this.addon.preset.options,
470+
headers: this.addon.headers,
464471
})
465472
);
466473
}

packages/core/src/presets/mediafusion.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
Stream,
77
ParsedStream,
88
} from '../db/index.js';
9-
import { baseOptions, Preset } from './preset.js';
9+
import { baseOptions, CacheKeyRequestOptions, Preset } from './preset.js';
1010
import { createLogger, getSimpleTextHash } from '../utils/index.js';
1111
import { constants, ServiceId } from '../utils/index.js';
1212
import { config as appConfig } from '../config/index.js';
@@ -407,6 +407,16 @@ export class MediaFusionPreset extends Preset {
407407
};
408408
}
409409

410+
public static getCacheKey(
411+
options: CacheKeyRequestOptions
412+
): string | undefined {
413+
const { headers } = options;
414+
if (headers?.encoded_user_data) {
415+
return getSimpleTextHash(headers.encoded_user_data);
416+
}
417+
return undefined;
418+
}
419+
410420
private static generateManifestUrl(
411421
options: Record<string, any>,
412422
encodedUserData: string
@@ -415,7 +425,7 @@ export class MediaFusionPreset extends Preset {
415425
if (url.endsWith('/manifest.json')) {
416426
return url;
417427
}
418-
return `${url}/${getSimpleTextHash(encodedUserData)}/manifest.json`;
428+
return `${url}/manifest.json`;
419429
}
420430

421431
private static generateEncodedUserData(

packages/core/src/presets/preset.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export interface CacheKeyRequestOptions {
105105
type: string;
106106
id: string;
107107
options: Record<string, any>;
108+
headers: Record<string, string> | undefined;
108109
extras?: string;
109110
}
110111

0 commit comments

Comments
 (0)