diff --git a/src/controller/ConfigureController.ts b/src/controller/ConfigureController.ts index 6826eb3..7c65262 100644 --- a/src/controller/ConfigureController.ts +++ b/src/controller/ConfigureController.ts @@ -1,6 +1,6 @@ import { Request, Response, Router } from 'express'; import { landingTemplate } from '../landingTemplate'; -import { buildManifest } from '../utils'; +import { buildManifest, getDefaultConfig } from '../utils'; import { Handler } from '../handler'; import { Config } from '../types'; @@ -19,7 +19,7 @@ export class ConfigureController { } private readonly getConfigure = (req: Request, res: Response) => { - const config: Config = JSON.parse(req.params['config'] || '{}'); + const config: Config = JSON.parse(req.params['config'] || JSON.stringify(getDefaultConfig())); const manifest = buildManifest(this.handlers, config); diff --git a/src/controller/ManifestController.ts b/src/controller/ManifestController.ts index 1edd1dc..dee40b9 100644 --- a/src/controller/ManifestController.ts +++ b/src/controller/ManifestController.ts @@ -1,5 +1,5 @@ import { Request, Response, Router } from 'express'; -import { buildManifest } from '../utils'; +import { buildManifest, getDefaultConfig } from '../utils'; import { Handler } from '../handler'; import { Config } from '../types'; @@ -18,7 +18,7 @@ export class ManifestController { } private readonly getManifest = (req: Request, res: Response) => { - const config: Config = JSON.parse(req.params['config'] || '{}'); + const config: Config = JSON.parse(req.params['config'] || JSON.stringify(getDefaultConfig())); const manifest = buildManifest(this.handlers, config); diff --git a/src/controller/StreamController.ts b/src/controller/StreamController.ts index b509747..d5009ad 100644 --- a/src/controller/StreamController.ts +++ b/src/controller/StreamController.ts @@ -2,7 +2,7 @@ import { Request, Response, Router } from 'express'; import winston from 'winston'; import { Handler } from '../handler'; import { Config, Context } from '../types'; -import { envIsProd, ImdbId, StreamResolver } from '../utils'; +import { envIsProd, getDefaultConfig, ImdbId, StreamResolver } from '../utils'; import { ContentType } from 'stremio-addon-sdk'; export class StreamController { @@ -23,7 +23,7 @@ export class StreamController { } private readonly getStream = async (req: Request, res: Response) => { - const config: Config = JSON.parse(req.params['config'] || '{}'); + const config: Config = req.params['config'] ? JSON.parse(req.params['config']) : getDefaultConfig(); const type: ContentType = (req.params['type'] || '') as ContentType; const id: string = req.params['id'] || ''; diff --git a/src/utils/config.test.ts b/src/utils/config.test.ts new file mode 100644 index 0000000..e894e9a --- /dev/null +++ b/src/utils/config.test.ts @@ -0,0 +1,7 @@ +import { getDefaultConfig } from './config'; + +describe('getDefaultConfig', () => { + test('has English enabled', () => { + expect(getDefaultConfig().en).toBe('on'); + }); +}); diff --git a/src/utils/config.ts b/src/utils/config.ts new file mode 100644 index 0000000..ee6296f --- /dev/null +++ b/src/utils/config.ts @@ -0,0 +1,5 @@ +import { Config } from '../types'; + +export const getDefaultConfig = (): Config => { + return { en: 'on' }; +}; diff --git a/src/utils/index.ts b/src/utils/index.ts index ed3c093..db2d57c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,5 +1,6 @@ export * from './Fetcher'; export * from './StreamResolver'; +export * from './config'; export * from './embed'; export * from './env'; export * from './id';