revert: Revert "feat: allow to disable cache"
This reverts commit 4078f0c404.
This commit is contained in:
parent
7cdc3e1acc
commit
c4e25d25e8
8 changed files with 11 additions and 140 deletions
|
|
@ -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<UrlResult[]>(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();
|
||||
|
|
|
|||
|
|
@ -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<SourceResult[]>(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) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export type CustomManifest = Manifest & {
|
|||
};
|
||||
};
|
||||
|
||||
export type Config = Partial<Record<CountryCode | 'showErrors' | 'includeExternalUrls' | 'mediaFlowProxyUrl' | 'mediaFlowProxyPassword' | 'proxyConfig' | 'noCache', string> & Record<`disableExtractor_${string}`, string>>;
|
||||
export type Config = Partial<Record<CountryCode | 'showErrors' | 'includeExternalUrls' | 'mediaFlowProxyUrl' | 'mediaFlowProxyPassword' | 'proxyConfig', string> & Record<`disableExtractor_${string}`, string>>;
|
||||
|
||||
export enum CountryCode {
|
||||
multi = 'multi',
|
||||
|
|
|
|||
|
|
@ -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 { createDispatcher } from './dispatcher';
|
||||
import { envGet } from './env';
|
||||
|
||||
|
|
@ -234,8 +233,8 @@ export class Fetcher {
|
|||
|
||||
const cacheKey = this.determineCacheKey(url, init);
|
||||
let httpCacheItem = await this.cacheGet(cacheKey);
|
||||
const disableCache = init?.noCache ?? noCache(ctx.config);
|
||||
if (httpCacheItem && !disableCache) {
|
||||
const noCache = init?.noCache ?? false;
|
||||
if (httpCacheItem && !noCache) {
|
||||
this.logger.info(`Cached fetch ${request.method} ${url}: ${httpCacheItem.status} (${httpCacheItem.statusText})`, ctx);
|
||||
return this.handleHttpCacheItem(ctx, httpCacheItem, url, init);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,11 +72,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.
|
||||
|
||||
|
|
@ -136,11 +131,6 @@ exports[`buildManifest disable extractors 1`] = `
|
|||
"title": "Proxy Config",
|
||||
"type": "text",
|
||||
},
|
||||
{
|
||||
"key": "noCache",
|
||||
"title": "Disable cache",
|
||||
"type": "checkbox",
|
||||
},
|
||||
{
|
||||
"default": "checked",
|
||||
"key": "disableExtractor_doodstream",
|
||||
|
|
@ -155,9 +145,10 @@ exports[`buildManifest disable extractors 1`] = `
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`buildManifest has checked includeExternalUrls 1`] = `
|
||||
exports[`buildManifest has checked showErrors and includeExternalUrls 1`] = `
|
||||
[
|
||||
{
|
||||
"default": "checked",
|
||||
"key": "showErrors",
|
||||
"title": "Show errors",
|
||||
"type": "checkbox",
|
||||
|
|
@ -186,89 +177,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",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`buildManifest has checked showErrors 1`] = `
|
||||
[
|
||||
{
|
||||
"default": "checked",
|
||||
"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",
|
||||
},
|
||||
{
|
||||
"key": "noCache",
|
||||
"title": "Disable cache",
|
||||
"type": "checkbox",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
|
|
@ -319,11 +227,6 @@ exports[`buildManifest has checked source with appropriate config 1`] = `
|
|||
"title": "Proxy Config",
|
||||
"type": "text",
|
||||
},
|
||||
{
|
||||
"key": "noCache",
|
||||
"title": "Disable cache",
|
||||
"type": "checkbox",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
|
|
@ -382,11 +285,6 @@ exports[`buildManifest has unchecked source without a config 1`] = `
|
|||
"title": "Proxy Config",
|
||||
"type": "text",
|
||||
},
|
||||
{
|
||||
"key": "noCache",
|
||||
"title": "Disable cache",
|
||||
"type": "checkbox",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
||||
|
|
@ -420,10 +318,5 @@ exports[`buildManifest showErrors and includeExternalUrls are unchecked by defau
|
|||
"title": "Proxy Config",
|
||||
"type": "text",
|
||||
},
|
||||
{
|
||||
"key": "noCache",
|
||||
"title": "Disable cache",
|
||||
"type": "checkbox",
|
||||
},
|
||||
]
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -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}`;
|
||||
|
|
|
|||
|
|
@ -50,20 +50,8 @@ describe('buildManifest', () => {
|
|||
expect(manifest.config).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('has checked showErrors', () => {
|
||||
const manifest = buildManifest([], [], { showErrors: 'on' });
|
||||
|
||||
expect(manifest.config).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('has checked includeExternalUrls', () => {
|
||||
const manifest = buildManifest([], [], { includeExternalUrls: 'on' });
|
||||
|
||||
expect(manifest.config).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('has checked noCache', () => {
|
||||
const manifest = buildManifest([], [], { noCache: 'on' });
|
||||
test('has checked showErrors and includeExternalUrls', () => {
|
||||
const manifest = buildManifest([], [], { showErrors: 'on', includeExternalUrls: 'on' });
|
||||
|
||||
expect(manifest.config).toMatchSnapshot();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -96,13 +96,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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue