diff --git a/src/clients/radarr-client.ts b/src/clients/radarr-client.ts index fd6d6d3..e76e68f 100644 --- a/src/clients/radarr-client.ts +++ b/src/clients/radarr-client.ts @@ -1,11 +1,18 @@ import { KyHttpClient } from "../__generated__/ky-client"; import { Api } from "../__generated__/radarr/Api"; -import { CustomFormatResource, QualityDefinitionResource, QualityProfileResource } from "../__generated__/radarr/data-contracts"; +import { + CustomFormatResource, + LanguageResource, + QualityDefinitionResource, + QualityProfileResource, +} from "../__generated__/radarr/data-contracts"; import { logger } from "../logger"; +import { cloneWithJSON } from "../util"; import { IArrClient, validateClientParams } from "./unified-client"; -export class RadarrClient implements IArrClient { +export class RadarrClient implements IArrClient { private api!: Api; + private languageMap: Map = new Map(); constructor(baseUrl: string, apiKey: string) { this.initialize(baseUrl, apiKey); @@ -24,6 +31,10 @@ export class RadarrClient implements IArrClient { - if (profile.language) { + async createQualityProfile(profile: QualityProfileResource): Promise { + const cloned = cloneWithJSON(profile); + + if (this.languageMap.size <= 0) { + const languages = await this.getLanguages(); + this.languageMap = new Map(languages.map((i) => [i.name!, i])); } - return this.api.v3QualityprofileCreate(profile); + + if (profile.language == null) { + cloned.language = this.languageMap.get("Any"); + } + + return this.api.v3QualityprofileCreate(cloned); } updateQualityProfile(id: string, profile: QualityProfileResource): Promise { diff --git a/src/clients/readarr-client.ts b/src/clients/readarr-client.ts index dd4f062..63c58cd 100644 --- a/src/clients/readarr-client.ts +++ b/src/clients/readarr-client.ts @@ -2,6 +2,7 @@ import { KyHttpClient } from "../__generated__/ky-client"; import { Api } from "../__generated__/readarr/Api"; import { CustomFormatResource, + LanguageResource, MetadataProfileResource, QualityDefinitionResource, QualityProfileResource, @@ -9,7 +10,9 @@ import { import { logger } from "../logger"; import { IArrClient, validateClientParams } from "./unified-client"; -export class ReadarrClient implements IArrClient { +export class ReadarrClient + implements IArrClient +{ private api!: Api; constructor(baseUrl: string, apiKey: string) { @@ -29,6 +32,10 @@ export class ReadarrClient implements IArrClient { +export class SonarrClient implements IArrClient { private api!: Api; constructor(baseUrl: string, apiKey: string) { @@ -30,6 +35,10 @@ export class SonarrClient implements IArrClient { // Quality Management getQualityDefinitions(): Promise; @@ -104,6 +111,8 @@ export interface IArrClient< updateCustomFormat(id: string, format: CF): Promise; deleteCustomFormat(id: string): Promise; + getLanguages(): Promise; + // System/Health Check getSystemStatus(): Promise; testConnection(): Promise; @@ -138,6 +147,10 @@ export class UnifiedClient implements IArrClient { return this.api as T; } + async getLanguages() { + return this.api.getLanguages(); + } + async getQualityDefinitions() { return await this.api.getQualityDefinitions(); } diff --git a/src/clients/whisparr-client.ts b/src/clients/whisparr-client.ts index 8e21191..1e08187 100644 --- a/src/clients/whisparr-client.ts +++ b/src/clients/whisparr-client.ts @@ -1,11 +1,29 @@ import { KyHttpClient } from "../__generated__/ky-client"; import { Api } from "../__generated__/whisparr/Api"; -import { CustomFormatResource, QualityDefinitionResource, QualityProfileResource } from "../__generated__/whisparr/data-contracts"; +import { + CustomFormatResource, + LanguageResource, + QualityDefinitionResource, + QualityProfileResource, +} from "../__generated__/whisparr/data-contracts"; import { logger } from "../logger"; +import { cloneWithJSON } from "../util"; import { IArrClient, validateClientParams } from "./unified-client"; -export class WhisparrClient implements IArrClient { +/** + * Overwrite wrong types for now + */ +declare module "../__generated__/whisparr/data-contracts" { + export interface QualityProfileResource { + language?: Language; + } +} + +export class WhisparrClient + implements IArrClient +{ private api!: Api; + private languageMap: Map = new Map(); constructor(baseUrl: string, apiKey: string) { this.initialize(baseUrl, apiKey); @@ -24,6 +42,10 @@ export class WhisparrClient implements IArrClient { + const cloned = cloneWithJSON(profile); + + if (this.languageMap.size <= 0) { + const languages = await this.getLanguages(); + this.languageMap = new Map(languages.map((i) => [i.name!, i])); + } + + if (profile.language == null) { + cloned.language = this.languageMap.get("Any"); + } + + return this.api.v3QualityprofileCreate(cloned); } updateQualityProfile(id: string, profile: QualityProfileResource) {