mirror of
https://github.com/zoriya/flood.git
synced 2025-12-05 23:06:20 +00:00
fix: resume and pause does not work with qbittorrent 5 (#801)
close #800
This commit is contained in:
@@ -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<string | undefined> = Promise.resolve(undefined);
|
||||
private isMainDataPending = false;
|
||||
|
||||
@@ -118,6 +120,17 @@ class ClientRequestManager {
|
||||
});
|
||||
}
|
||||
|
||||
async getApiVersion(): Promise<void> {
|
||||
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<QBittorrentTorrentInfos> {
|
||||
return axios
|
||||
.post<QBittorrentTorrentInfos>(`${this.apiBase}/torrents/info`, null, {
|
||||
@@ -293,9 +306,10 @@ class ClientRequestManager {
|
||||
}
|
||||
|
||||
async torrentsPause(hashes: Array<string>): Promise<void> {
|
||||
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<string>): Promise<void> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
16
server/services/qBittorrent/util/apiVersionCheck.ts
Normal file
16
server/services/qBittorrent/util/apiVersionCheck.ts
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user