diff --git a/server/services/qBittorrent/clientRequestManager.ts b/server/services/qBittorrent/clientRequestManager.ts index 8aff72766..4bc35f2ed 100644 --- a/server/services/qBittorrent/clientRequestManager.ts +++ b/server/services/qBittorrent/clientRequestManager.ts @@ -20,6 +20,7 @@ import type { QBittorrentTorrentTrackers, } from './types/QBittorrentTorrentsMethods'; import type {QBittorrentTransferInfo} from './types/QBittorrentTransferMethods'; +import {isApiVersionAtLeast} from './util/apiVersionCheck'; const EMPTY_SERVER_STATE = { dl_info_speed: 0, @@ -35,6 +36,7 @@ const EMPTY_SERVER_STATE = { class ClientRequestManager { private connectionSettings: QBittorrentConnectionSettings; private apiBase: string; + private apiVersion: string | null = null; private authCookie: Promise = Promise.resolve(undefined); private isMainDataPending = false; @@ -118,6 +120,17 @@ class ClientRequestManager { }); } + async getApiVersion(): Promise { + try { + const {data} = await axios.get(`${this.apiBase}/app/webapiVersion`, { + headers: await this.getRequestHeaders(), + }); + this.apiVersion = data; + } catch (error) { + this.apiVersion = null; + } + } + async getTorrentInfos(): Promise { return axios .post(`${this.apiBase}/torrents/info`, null, { @@ -293,9 +306,10 @@ class ClientRequestManager { } async torrentsPause(hashes: Array): Promise { + const method = isApiVersionAtLeast(this.apiVersion, '2.11.0') ? 'stop' : 'pause'; return axios .post( - `${this.apiBase}/torrents/pause`, + `${this.apiBase}/torrents/${method}`, new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), }), @@ -309,9 +323,10 @@ class ClientRequestManager { } async torrentsResume(hashes: Array): Promise { + const method = isApiVersionAtLeast(this.apiVersion, '2.11.0') ? 'start' : 'resume'; return axios .post( - `${this.apiBase}/torrents/resume`, + `${this.apiBase}/torrents/${method}`, new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), }), @@ -608,6 +623,7 @@ class ClientRequestManager { this.connectionSettings = connectionSettings; this.apiBase = `${connectionSettings.url}/api/v2`; this.updateAuthCookie().catch(() => undefined); + this.getApiVersion(); } } diff --git a/server/services/qBittorrent/util/apiVersionCheck.ts b/server/services/qBittorrent/util/apiVersionCheck.ts new file mode 100644 index 000000000..9ba6a3d38 --- /dev/null +++ b/server/services/qBittorrent/util/apiVersionCheck.ts @@ -0,0 +1,16 @@ +export function isApiVersionAtLeast(currentVersion: string | null, targetVersion: string): boolean { + if (!currentVersion) { + return false; + } + const v1 = currentVersion.split('.').map(Number); + const v2 = targetVersion.split('.').map(Number); + + for (let i = 0; i < Math.max(v1.length, v2.length); i++) { + const num1 = v1[i] || 0; + const num2 = v2[i] || 0; + + if (num1 > num2) return true; + if (num1 < num2) return false; + } + return true; +}