diff --git a/src/api.ts b/src/api.ts index efcaa22..301f84b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -25,14 +25,6 @@ export const getArrApi = (): SonarrApi | RadarrApi | WhisparrA throw new Error("Please configure API first."); }; -export const getSonarrApi = () => { - if (sonarrClient) { - return sonarrClient; - } - - throw new Error("Please configure API first."); -}; - const validateParams = (url: string, apiKey: string, arrType: ArrType) => { const arrLabel = arrType.toLowerCase(); @@ -70,60 +62,6 @@ const handleErrorApi = (error: any, arrType: ArrType) => { throw new Error(message); }; -export const configureSonarrApi = async (url: string, apiKey: string) => { - unsetApi(); - validateParams(url, apiKey, "SONARR"); - - const httpClient = new KyHttpClient({ - headers: { - "X-Api-Key": apiKey, - }, - prefixUrl: url, - }); - const api = new SonarrApi(httpClient); - - sonarrClient = api; - - try { - await sonarrClient.v3MetadataList(); - } catch (error: any) { - handleErrorApi(error, "SONARR"); - } - - return sonarrClient; -}; - -export const getRadarrpi = () => { - if (radarrClient) { - return radarrClient; - } - - throw new Error("Please configure API first."); -}; - -export const configureRadarrApi = async (url: string, apiKey: string) => { - unsetApi(); - validateParams(url, apiKey, "RADARR"); - - const httpClient = new KyHttpClient({ - headers: { - "X-Api-Key": apiKey, - }, - prefixUrl: url, - }); - const api = new RadarrApi(httpClient); - - radarrClient = api; - - try { - await radarrClient.v3MetadataList(); - } catch (error: any) { - handleErrorApi(error, "RADARR"); - } - - return radarrClient; -}; - export const configureApi = async (type: ArrType, url: string, apiKey: string) => { unsetApi(); validateParams(url, apiKey, type); diff --git a/src/index.ts b/src/index.ts index 2975d45..e72acb6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import "dotenv/config"; import fs from "node:fs"; import { MergedCustomFormatResource } from "./__generated__/mergedTypes"; -import { configureApi, configureRadarrApi, configureSonarrApi, getArrApi, unsetApi } from "./api"; +import { configureApi, getArrApi, unsetApi } from "./api"; import { getConfig, validateConfig } from "./config"; import { calculateCFsToManage, loadCFFromConfig, loadLocalCfs, loadServerCustomFormats, manageCf, mergeCfSources } from "./custom-formats"; import { loadLocalRecyclarrTemplate } from "./local-importer"; @@ -312,7 +312,7 @@ const run = async () => { for (const [instanceName, instance] of Object.entries(sonarrConfig)) { logger.info(`Processing Sonarr Instance: ${instanceName}`); - await configureSonarrApi(instance.base_url, instance.api_key); + await configureApi("SONARR", instance.base_url, instance.api_key); await pipeline(instance, "SONARR"); unsetApi(); } @@ -327,7 +327,7 @@ const run = async () => { for (const [instanceName, instance] of Object.entries(radarrConfig)) { logger.info(`Processing Radarr Instance: ${instanceName}`); - await configureRadarrApi(instance.base_url, instance.api_key); + await configureApi("RADARR", instance.base_url, instance.api_key); await pipeline(instance, "RADARR"); unsetApi(); }