refactor: strictly type ContentType

This commit is contained in:
WebStreamr 2025-06-08 07:54:17 +00:00
parent 82c75b0654
commit 62f18ece85
No known key found for this signature in database
13 changed files with 27 additions and 15 deletions

View file

@ -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 = {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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)[]>;
}

View file

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

View file

@ -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<ResolveResponse> => {
readonly resolve = async (ctx: Context, handlers: Handler[], type: ContentType, id: string): Promise<ResolveResponse> => {
if (handlers.length === 0) {
return {
streams: [