From 62f18ece85eaa3c8721e27500674e1f028e6a69d Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Sun, 8 Jun 2025 07:54:17 +0000 Subject: [PATCH] refactor: strictly type `ContentType` --- src/controller/StreamController.ts | 3 ++- src/handler/CineHDPlus.ts | 3 ++- src/handler/Eurostreaming.ts | 3 ++- src/handler/Frembed.ts | 3 ++- src/handler/FrenchCloud.ts | 3 ++- src/handler/KinoKiste.ts | 3 ++- src/handler/MeineCloud.ts | 3 ++- src/handler/MostraGuarda.ts | 3 ++- src/handler/Soaper.ts | 3 ++- src/handler/VerHdLink.ts | 3 ++- src/handler/types.ts | 5 +++-- src/utils/StreamResolver.test.ts | 3 ++- src/utils/StreamResolver.ts | 4 ++-- 13 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/controller/StreamController.ts b/src/controller/StreamController.ts index f27883b..e3ff813 100644 --- a/src/controller/StreamController.ts +++ b/src/controller/StreamController.ts @@ -3,6 +3,7 @@ import winston from 'winston'; import { Handler } from '../handler'; import { Config, Context } from '../types'; import { envIsProd, StreamResolver } from '../utils'; +import { ContentType } from 'stremio-addon-sdk'; export class StreamController { public readonly router: Router; @@ -23,7 +24,7 @@ export class StreamController { private readonly getStream = async (req: Request, res: Response) => { const config: Config = JSON.parse(req.params['config'] || '{}'); - const type: string = req.params['type'] || ''; + const type: ContentType = (req.params['type'] || '') as ContentType; const id: string = req.params['id'] || ''; const ctx: Context = { diff --git a/src/handler/CineHDPlus.ts b/src/handler/CineHDPlus.ts index 4a0fed4..e91779b 100644 --- a/src/handler/CineHDPlus.ts +++ b/src/handler/CineHDPlus.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { Fetcher, ImdbId, parseImdbId } from '../utils'; @@ -9,7 +10,7 @@ export class CineHDPlus implements Handler { readonly label = 'CineHDPlus'; - readonly contentTypes = ['series']; + readonly contentTypes: ContentType[] = ['series']; readonly countryCodes: CountryCode[] = ['es', 'mx']; diff --git a/src/handler/Eurostreaming.ts b/src/handler/Eurostreaming.ts index d4451df..bd58bbf 100644 --- a/src/handler/Eurostreaming.ts +++ b/src/handler/Eurostreaming.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { ImdbId, parseImdbId, Fetcher } from '../utils'; @@ -9,7 +10,7 @@ export class Eurostreaming implements Handler { readonly label = 'Eurostreaming'; - readonly contentTypes = ['series']; + readonly contentTypes: ContentType[] = ['series']; readonly countryCodes: CountryCode[] = ['it']; diff --git a/src/handler/Frembed.ts b/src/handler/Frembed.ts index 4f76d95..b7f2ee8 100644 --- a/src/handler/Frembed.ts +++ b/src/handler/Frembed.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import { Handler } from './types'; import { parseImdbId, Fetcher, getTmdbIdFromImdbId, TmdbId, parseTmdbId } from '../utils'; import { ExtractorRegistry } from '../extractor'; @@ -8,7 +9,7 @@ export class Frembed implements Handler { readonly label = 'Frembed'; - readonly contentTypes = ['series']; + readonly contentTypes: ContentType[] = ['series']; readonly countryCodes: CountryCode[] = ['fr']; diff --git a/src/handler/FrenchCloud.ts b/src/handler/FrenchCloud.ts index cc2bac5..e1adfe9 100644 --- a/src/handler/FrenchCloud.ts +++ b/src/handler/FrenchCloud.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { Fetcher, parseImdbId } from '../utils'; @@ -9,7 +10,7 @@ export class FrenchCloud implements Handler { readonly label = 'FrenchCloud'; - readonly contentTypes = ['movie']; + readonly contentTypes: ContentType[] = ['movie']; readonly countryCodes: CountryCode[] = ['fr']; diff --git a/src/handler/KinoKiste.ts b/src/handler/KinoKiste.ts index ceae6f3..2fef2f7 100644 --- a/src/handler/KinoKiste.ts +++ b/src/handler/KinoKiste.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { ImdbId, parseImdbId, Fetcher } from '../utils'; @@ -9,7 +10,7 @@ export class KinoKiste implements Handler { readonly label = 'KinoKiste'; - readonly contentTypes = ['series']; + readonly contentTypes: ContentType[] = ['series']; readonly countryCodes: CountryCode[] = ['de']; diff --git a/src/handler/MeineCloud.ts b/src/handler/MeineCloud.ts index 1528173..d1c8e7e 100644 --- a/src/handler/MeineCloud.ts +++ b/src/handler/MeineCloud.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { Fetcher, parseImdbId } from '../utils'; @@ -9,7 +10,7 @@ export class MeineCloud implements Handler { readonly label = 'MeineCloud'; - readonly contentTypes = ['movie']; + readonly contentTypes: ContentType[] = ['movie']; readonly countryCodes: CountryCode[] = ['de']; diff --git a/src/handler/MostraGuarda.ts b/src/handler/MostraGuarda.ts index 10aaedf..690e2db 100644 --- a/src/handler/MostraGuarda.ts +++ b/src/handler/MostraGuarda.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { Fetcher, parseImdbId } from '../utils'; @@ -9,7 +10,7 @@ export class MostraGuarda implements Handler { readonly label = 'MostraGuarda'; - readonly contentTypes = ['movie']; + readonly contentTypes: ContentType[] = ['movie']; readonly countryCodes: CountryCode[] = ['it']; diff --git a/src/handler/Soaper.ts b/src/handler/Soaper.ts index d00bb54..d747d4d 100644 --- a/src/handler/Soaper.ts +++ b/src/handler/Soaper.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { @@ -17,7 +18,7 @@ export class Soaper implements Handler { readonly label = 'Soaper'; - readonly contentTypes = ['movie', 'series']; + readonly contentTypes: ContentType[] = ['movie', 'series']; readonly countryCodes: CountryCode[] = ['en']; diff --git a/src/handler/VerHdLink.ts b/src/handler/VerHdLink.ts index a242bbb..13d5fe3 100644 --- a/src/handler/VerHdLink.ts +++ b/src/handler/VerHdLink.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import * as cheerio from 'cheerio'; import { Handler } from './types'; import { Fetcher, parseImdbId } from '../utils'; @@ -9,7 +10,7 @@ export class VerHdLink implements Handler { readonly label = 'VerHdLink'; - readonly contentTypes = ['movie']; + readonly contentTypes: ContentType[] = ['movie']; readonly countryCodes: CountryCode[] = ['es', 'mx']; diff --git a/src/handler/types.ts b/src/handler/types.ts index 78e4dd0..9208875 100644 --- a/src/handler/types.ts +++ b/src/handler/types.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import { Context, CountryCode, UrlResult } from '../types'; export interface Handler { @@ -5,9 +6,9 @@ export interface Handler { readonly label: string; - readonly contentTypes: string[]; + readonly contentTypes: ContentType[]; readonly countryCodes: CountryCode[]; - readonly handle: (ctx: Context, type: string, id: string) => Promise<(UrlResult | undefined)[]>; + readonly handle: (ctx: Context, type: ContentType, id: string) => Promise<(UrlResult | undefined)[]>; } diff --git a/src/utils/StreamResolver.test.ts b/src/utils/StreamResolver.test.ts index 8f60009..6a0d81b 100644 --- a/src/utils/StreamResolver.test.ts +++ b/src/utils/StreamResolver.test.ts @@ -1,3 +1,4 @@ +import { ContentType } from 'stremio-addon-sdk'; import winston from 'winston'; import { ExtractorRegistry } from '../extractor'; import { StreamResolver } from './StreamResolver'; @@ -57,7 +58,7 @@ describe('resolve', () => { readonly label = 'MockHandler'; - readonly contentTypes = ['movie']; + readonly contentTypes: ContentType[] = ['movie']; readonly countryCodes: CountryCode[] = ['de']; diff --git a/src/utils/StreamResolver.ts b/src/utils/StreamResolver.ts index ab1d87f..fa1e35d 100644 --- a/src/utils/StreamResolver.ts +++ b/src/utils/StreamResolver.ts @@ -1,4 +1,4 @@ -import { Stream } from 'stremio-addon-sdk'; +import { ContentType, Stream } from 'stremio-addon-sdk'; import winston from 'winston'; import bytes from 'bytes'; import { Context, TIMEOUT, UrlResult } from '../types'; @@ -19,7 +19,7 @@ export class StreamResolver { this.logger = logger; } - readonly resolve = async (ctx: Context, handlers: Handler[], type: string, id: string): Promise => { + readonly resolve = async (ctx: Context, handlers: Handler[], type: ContentType, id: string): Promise => { if (handlers.length === 0) { return { streams: [