From a9a4dc0b21494e31973c17d53c8b065f56ff5cc9 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Tue, 26 Sep 2023 02:25:04 -0400 Subject: [PATCH] Added native fetch to source tester --- run-source.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/run-source.ts b/run-source.ts index 0c86da0..e2a25be 100644 --- a/run-source.ts +++ b/run-source.ts @@ -268,7 +268,7 @@ async function runQuestions() { async function runCommandLine() { program - .option('-f, --fetcher ', 'Fetcher to use. Currently only \'node-fetch\' is suspported', 'node-fetch') + .option('-f, --fetcher ', 'Fetcher to use. Either \'native\' \'node-fetch\'', 'node-fetch') .option('-sid, --source-id ', 'ID for the source to use. Either an embed or provider', '') .option('-tid, --tmdb-id ', 'TMDB ID for the media to scrape. Only used if source is a provider', '') .option('-t, --type ', 'Media type. Either \'movie\' or \'show\'. Only used if source is a provider', 'movie') @@ -282,13 +282,8 @@ async function runCommandLine() { } async function processOptions(options: CommandLineArguments) { - if (options.fetcher !== 'node-fetch') { - // * Using native fetch in makeStandardFetcher throws the following TS error: - // * - // * Argument of type '(input: RequestInfo | URL, init?: RequestInit | undefined) => Promise' is not assignable to parameter of type 'typeof fetch'. - // * Property 'isRedirect' is missing in type '(input: RequestInfo | URL, init?: RequestInit | undefined) => Promise' but required in type 'typeof fetch'. ts(2345) - // * index.d.ts(221, 14): 'isRedirect' is declared here. - throw new Error('Fetcher must be node-fetch'); + if (options.fetcher !== 'node-fetch' && options.fetcher !== 'native') { + throw new Error('Fetcher must be either \'native\' or \'node-fetch\''); } if (!options.sourceId.trim()) { @@ -341,7 +336,14 @@ async function processOptions(options: CommandLineArguments) { } } - const fetcher = makeStandardFetcher(nodeFetch); + let fetcher; + + if (options.fetcher === 'native') { + fetcher = makeStandardFetcher(fetch as any); + } else { + fetcher = makeStandardFetcher(nodeFetch); + } + const providers = makeProviders({ fetcher: fetcher, target: targets.NATIVE