chore: introduce config helper, enable English by default

This commit is contained in:
WebStreamr 2025-06-08 14:09:10 +00:00
parent 968b7d4bc0
commit 48209ac876
No known key found for this signature in database
6 changed files with 19 additions and 6 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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'] || '';

7
src/utils/config.test.ts Normal file
View file

@ -0,0 +1,7 @@
import { getDefaultConfig } from './config';
describe('getDefaultConfig', () => {
test('has English enabled', () => {
expect(getDefaultConfig().en).toBe('on');
});
});

5
src/utils/config.ts Normal file
View file

@ -0,0 +1,5 @@
import { Config } from '../types';
export const getDefaultConfig = (): Config => {
return { en: 'on' };
};

View file

@ -1,5 +1,6 @@
export * from './Fetcher';
export * from './StreamResolver';
export * from './config';
export * from './embed';
export * from './env';
export * from './id';