From 357c5023e2390bc7cf9c50c199028c5b72d08882 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Mon, 20 Oct 2025 04:31:31 +1030 Subject: [PATCH] fix(arr): parameterise api version to let clients override --- src/routes/arr/test/+server.ts | 2 +- src/utils/arr/base.ts | 9 ++++++--- src/utils/arr/clients/lidarr.ts | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/routes/arr/test/+server.ts b/src/routes/arr/test/+server.ts index 45efc56..74dea5a 100644 --- a/src/routes/arr/test/+server.ts +++ b/src/routes/arr/test/+server.ts @@ -26,7 +26,7 @@ export const POST: RequestHandler = async ({ request }) => { if (isConnected) { return json({ success: true }); } else { - return json({ success: false, error: 'Connection test failed' }); + return json({ success: false, error: 'Connection test failed' }, { status: 400 }); } } catch (error) { return json( diff --git a/src/utils/arr/base.ts b/src/utils/arr/base.ts index 5006ea0..09fa7f5 100644 --- a/src/utils/arr/base.ts +++ b/src/utils/arr/base.ts @@ -8,6 +8,7 @@ import { logger } from '$logger'; */ export class BaseArrClient extends BaseHttpClient { private apiKey: string; + protected apiVersion: string = 'v3'; // Default to v3, can be overridden by subclasses constructor(url: string, apiKey: string) { super(url, { @@ -20,12 +21,13 @@ export class BaseArrClient extends BaseHttpClient { /** * Test connection to the arr instance - * Calls /api/v3/system/status endpoint + * Calls /api/{version}/system/status endpoint + * Note: This method has built-in retry logic (3 attempts by default) * @returns true if connection successful, false otherwise */ async testConnection(): Promise { try { - const status = await this.get('/api/v3/system/status'); + const status = await this.get(`/api/${this.apiVersion}/system/status`); await logger.info(`Connection successful to ${this.baseUrl}`, { source: 'BaseArrClient', @@ -38,7 +40,8 @@ export class BaseArrClient extends BaseHttpClient { return true; } catch (error) { - await logger.error(`Connection failed to ${this.baseUrl}`, { + // Only log after all retries are exhausted + await logger.error(`Connection failed to ${this.baseUrl} after retries`, { source: 'BaseArrClient', meta: error }); diff --git a/src/utils/arr/clients/lidarr.ts b/src/utils/arr/clients/lidarr.ts index b9b61a7..3f6bc7a 100644 --- a/src/utils/arr/clients/lidarr.ts +++ b/src/utils/arr/clients/lidarr.ts @@ -3,7 +3,10 @@ import { BaseArrClient } from '../base.ts'; /** * Lidarr API client * Extends BaseArrClient with Lidarr-specific API methods + * Note: Lidarr uses API v1, not v3 like other *arr apps */ export class LidarrClient extends BaseArrClient { + protected apiVersion: string = 'v1'; // Lidarr uses v1 API + // Specific API methods will be implemented here as needed }