diff --git a/src/controller/StreamController.ts b/src/controller/StreamController.ts index 7b204fa..e7086ff 100644 --- a/src/controller/StreamController.ts +++ b/src/controller/StreamController.ts @@ -3,7 +3,7 @@ import { Request, Response, Router } from 'express'; import { ContentType } from 'stremio-addon-sdk'; import winston from 'winston'; import { Source } from '../source'; -import { contextFromRequestAndResponse, envIsProd, Id, ImdbId, noCache, StreamResolver, TmdbId } from '../utils'; +import { contextFromRequestAndResponse, envIsProd, Id, ImdbId, StreamResolver, TmdbId } from '../utils'; export class StreamController { public readonly router: Router; @@ -53,9 +53,7 @@ export class StreamController { await mutex.runExclusive(async () => { const { streams, ttl } = await this.streamResolver.resolve(ctx, sources, type, id); - if (noCache(ctx.config)) { - res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0'); - } else if (ttl && envIsProd()) { + if (ttl && envIsProd()) { res.setHeader('Cache-Control', `max-age=${Math.floor(ttl / 1000)}, public`); } diff --git a/src/extractor/ExtractorRegistry.ts b/src/extractor/ExtractorRegistry.ts index 96a45ad..b65bc83 100644 --- a/src/extractor/ExtractorRegistry.ts +++ b/src/extractor/ExtractorRegistry.ts @@ -3,7 +3,7 @@ import KeyvSqlite from '@keyv/sqlite'; import { Cacheable, CacheableMemory, Keyv } from 'cacheable'; import winston from 'winston'; import { Context, Meta, UrlResult } from '../types'; -import { getCacheDir, isExtractorDisabled, noCache } from '../utils'; +import { getCacheDir, isExtractorDisabled } from '../utils'; import { Extractor } from './Extractor'; export class ExtractorRegistry { @@ -41,7 +41,7 @@ export class ExtractorRegistry { const storedDataRaw = await this.urlResultCache.getRaw(cacheKey); const expires = storedDataRaw?.expires; - if (storedDataRaw && expires && !noCache(ctx.config)) { + if (storedDataRaw && expires) { // Ignore the cache randomly after at least 2/3 of the TTL passed to start refreshing results slowly const refreshTimestamp = this.randomInteger(expires - extractor.ttl * (2 / 3), expires); const now = Date.now(); diff --git a/src/source/Source.ts b/src/source/Source.ts index 2ef1bd6..3f5feec 100644 --- a/src/source/Source.ts +++ b/src/source/Source.ts @@ -4,7 +4,7 @@ import { Cacheable, CacheableMemory, Keyv } from 'cacheable'; import { ContentType } from 'stremio-addon-sdk'; import { NotFoundError } from '../error'; import { Context, CountryCode, Meta } from '../types'; -import { getCacheDir, Id, noCache } from '../utils'; +import { getCacheDir, Id } from '../utils'; export interface SourceResult { url: URL; @@ -44,7 +44,7 @@ export abstract class Source { let sourceResults = (await Source.sourceResultCache.get(cacheKey)) ?.map(sourceResult => ({ ...sourceResult, url: new URL(sourceResult.url) })); - if (!sourceResults || noCache(ctx.config)) { + if (!sourceResults) { try { sourceResults = await this.handleInternal(ctx, type, id); } catch (error) { diff --git a/src/types.ts b/src/types.ts index c2421c7..3d46582 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,7 +17,7 @@ export type CustomManifest = Manifest & { }; }; -export type Config = Partial & Record<`disableExtractor_${string}`, string>>; +export type Config = Partial & Record<`disableExtractor_${string}`, string>>; export enum CountryCode { multi = 'multi', diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index 057fc86..b1acc27 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -7,7 +7,6 @@ import { fetch, Headers, RequestInit, Response } from 'undici'; import winston from 'winston'; import { BlockedError, HttpError, NotFoundError, QueueIsFullError, TimeoutError, TooManyRequestsError, TooManyTimeoutsError } from '../error'; import { BlockedReason, Context } from '../types'; -import { noCache } from './config'; import { getProxyAgent, getProxyForUrl } from './dispatcher'; import { envGet } from './env'; @@ -262,7 +261,7 @@ export class Fetcher { const cacheKey = this.determineCacheKey(url, init); let httpCacheItem = await this.cacheGet(cacheKey); - const disableCache = init?.noCache ?? noCache(ctx.config); + const disableCache = init?.noCache; if (httpCacheItem && !disableCache) { this.logger.info(`Cached fetch ${request.method} ${url}: ${httpCacheItem.status} (${httpCacheItem.statusText})`, ctx); return this.handleHttpCacheItem(ctx, httpCacheItem, url, init); diff --git a/src/utils/__snapshots__/manifest.test.ts.snap b/src/utils/__snapshots__/manifest.test.ts.snap index 69ad8d7..085d9cd 100644 --- a/src/utils/__snapshots__/manifest.test.ts.snap +++ b/src/utils/__snapshots__/manifest.test.ts.snap @@ -82,11 +82,6 @@ exports[`buildManifest default manifest 1`] = ` "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, ], "description": "Provides HTTP URLs from streaming websites. Configure add-on for additional languages. Add MediaFlow proxy for more URLs. @@ -147,11 +142,6 @@ exports[`buildManifest disable extractors 1`] = ` "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, { "default": "checked", "key": "disableExtractor_doodstream", @@ -197,50 +187,6 @@ exports[`buildManifest has checked includeExternalUrls 1`] = ` "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, -] -`; - -exports[`buildManifest has checked noCache 1`] = ` -[ - { - "key": "showErrors", - "title": "Show errors", - "type": "checkbox", - }, - { - "key": "includeExternalUrls", - "title": "Include external URLs in results", - "type": "checkbox", - }, - { - "default": "", - "key": "mediaFlowProxyUrl", - "title": "MediaFlow Proxy URL", - "type": "text", - }, - { - "default": "", - "key": "mediaFlowProxyPassword", - "title": "MediaFlow Proxy Password", - "type": "password", - }, - { - "default": "", - "key": "proxyConfig", - "title": "Proxy Config", - "type": "text", - }, - { - "default": "checked", - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, ] `; @@ -275,11 +221,6 @@ exports[`buildManifest has checked showErrors 1`] = ` "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, ] `; @@ -330,11 +271,6 @@ exports[`buildManifest has checked source with appropriate config 1`] = ` "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, ] `; @@ -393,11 +329,6 @@ exports[`buildManifest has unchecked source without a config 1`] = ` "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, ] `; @@ -431,10 +362,5 @@ exports[`buildManifest showErrors and includeExternalUrls are unchecked by defau "title": "Proxy Config", "type": "text", }, - { - "key": "noCache", - "title": "Disable cache", - "type": "checkbox", - }, ] `; diff --git a/src/utils/config.ts b/src/utils/config.ts index 2702554..fd503db 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -9,8 +9,6 @@ export const showErrors = (config: Config): boolean => 'showErrors' in config; export const showExternalUrls = (config: Config): boolean => 'includeExternalUrls' in config; -export const noCache = (config: Config): boolean => 'noCache' in config; - export const hasMultiEnabled = (config: Config): boolean => 'multi' in config; export const disableExtractorConfigKey = (extractor: Extractor): string => `disableExtractor_${extractor.id}`; diff --git a/src/utils/manifest.test.ts b/src/utils/manifest.test.ts index 9e71309..7f6f236 100644 --- a/src/utils/manifest.test.ts +++ b/src/utils/manifest.test.ts @@ -62,12 +62,6 @@ describe('buildManifest', () => { expect(manifest.config).toMatchSnapshot(); }); - test('has checked noCache', () => { - const manifest = buildManifest([], [], { noCache: 'on' }); - - expect(manifest.config).toMatchSnapshot(); - }); - test('disable extractors', () => { const extractors = [ new DoodStream(fetcher), diff --git a/src/utils/manifest.ts b/src/utils/manifest.ts index 8ec5c18..475e918 100644 --- a/src/utils/manifest.ts +++ b/src/utils/manifest.ts @@ -97,13 +97,6 @@ export const buildManifest = (sources: Source[], extractors: Extractor[], config default: config['proxyConfig'] ?? '', }); - manifest.config.push({ - key: 'noCache', - type: 'checkbox', - title: 'Disable cache', - ...('noCache' in config && { default: 'checked' }), - }); - extractors.forEach((extractor) => { if (extractor.id === 'external') { return;