fix(arr): parameterise api version to let clients override

This commit is contained in:
Sam Chau
2025-10-20 04:31:31 +10:30
parent c7f0698f2d
commit 357c5023e2
3 changed files with 10 additions and 4 deletions

View File

@@ -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(

View File

@@ -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<boolean> {
try {
const status = await this.get<ArrSystemStatus>('/api/v3/system/status');
const status = await this.get<ArrSystemStatus>(`/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
});

View File

@@ -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
}