diff --git a/server/services/qBittorrent/clientRequestManager.ts b/server/services/qBittorrent/clientRequestManager.ts index 1faca82dd..887f7b659 100644 --- a/server/services/qBittorrent/clientRequestManager.ts +++ b/server/services/qBittorrent/clientRequestManager.ts @@ -1,7 +1,6 @@ -import {URLSearchParams} from 'url'; - import axios from 'axios'; import FormData from 'form-data'; +import {URLSearchParams} from 'url'; import type {QBittorrentConnectionSettings} from '@shared/schema/ClientConnectionSettings'; @@ -129,34 +128,43 @@ class ClientRequestManager { async getTorrentContents(hash: string): Promise { return axios - .get(`${this.apiBase}/torrents/files`, { - params: { + .post( + `${this.apiBase}/torrents/files`, + new URLSearchParams({ hash: hash.toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then((res) => res.data); } async getTorrentProperties(hash: string): Promise { return axios - .get(`${this.apiBase}/torrents/properties`, { - params: { + .post( + `${this.apiBase}/torrents/properties`, + new URLSearchParams({ hash: hash.toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then((res) => res.data); } async getTorrentTrackers(hash: string): Promise { return axios - .get(`${this.apiBase}/torrents/trackers`, { - params: { + .post( + `${this.apiBase}/torrents/trackers`, + new URLSearchParams({ hash: hash.toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then((res) => res.data); } @@ -175,12 +183,15 @@ class ClientRequestManager { this.isMainDataPending = true; this.syncRids.mainData = this.syncRids.mainData.then((rid) => axios - .get(`${this.apiBase}/sync/maindata`, { - params: { - rid, + .post( + `${this.apiBase}/sync/maindata`, + new URLSearchParams({ + rid: `${rid}`, + }), + { + headers, }, - headers, - }) + ) .then(({data}) => { const { rid: newRid = 0, @@ -268,24 +279,30 @@ class ClientRequestManager { async syncTorrentPeers(hash: string): Promise { return axios - .get(`${this.apiBase}/sync/torrentPeers`, { - params: { + .post( + `${this.apiBase}/sync/torrentPeers`, + new URLSearchParams({ hash: hash.toLowerCase(), - rid: 0, + rid: '0', + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(({data}) => data.peers); } async torrentsPause(hashes: Array): Promise { return axios - .get(`${this.apiBase}/torrents/pause`, { - params: { + .post( + `${this.apiBase}/torrents/pause`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -293,12 +310,15 @@ class ClientRequestManager { async torrentsResume(hashes: Array): Promise { return axios - .get(`${this.apiBase}/torrents/resume`, { - params: { + .post( + `${this.apiBase}/torrents/resume`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -306,13 +326,16 @@ class ClientRequestManager { async torrentsDelete(hashes: Array, deleteFiles: boolean): Promise { return axios - .get(`${this.apiBase}/torrents/delete`, { - params: { + .post( + `${this.apiBase}/torrents/delete`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), deleteFiles: deleteFiles ? 'true' : 'false', + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -320,12 +343,15 @@ class ClientRequestManager { async torrentsRecheck(hashes: Array): Promise { return axios - .get(`${this.apiBase}/torrents/recheck`, { - params: { + .post( + `${this.apiBase}/torrents/recheck`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -333,13 +359,16 @@ class ClientRequestManager { async torrentsSetLocation(hashes: Array, location: string): Promise { return axios - .get(`${this.apiBase}/torrents/setLocation`, { - params: { + .post( + `${this.apiBase}/torrents/setLocation`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), location, + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -347,12 +376,15 @@ class ClientRequestManager { async torrentsSetTopPrio(hashes: Array): Promise { return axios - .get(`${this.apiBase}/torrents/topPrio`, { - params: { + .post( + `${this.apiBase}/torrents/topPrio`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -360,12 +392,15 @@ class ClientRequestManager { async torrentsSetBottomPrio(hashes: Array): Promise { return axios - .get(`${this.apiBase}/torrents/bottomPrio`, { - params: { + .post( + `${this.apiBase}/torrents/bottomPrio`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -426,13 +461,16 @@ class ClientRequestManager { async torrentsAddTags(hashes: Array, tags: Array): Promise { return axios - .get(`${this.apiBase}/torrents/addTags`, { - params: { + .post( + `${this.apiBase}/torrents/addTags`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), tags: tags.join(','), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -440,13 +478,16 @@ class ClientRequestManager { async torrentsRemoveTags(hashes: Array, tags?: Array): Promise { return axios - .get(`${this.apiBase}/torrents/removeTags`, { - params: { + .post( + `${this.apiBase}/torrents/removeTags`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), tags: tags?.join(','), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -455,13 +496,16 @@ class ClientRequestManager { async torrentsAddTrackers(hash: string, urls: Array): Promise { if (urls.length > 0) { return axios - .get(`${this.apiBase}/torrents/addTrackers`, { - params: { + .post( + `${this.apiBase}/torrents/addTrackers`, + new URLSearchParams({ hash: hash.toLowerCase(), urls: urls.join('\n'), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -471,12 +515,15 @@ class ClientRequestManager { async torrentsReannounce(hashes: Array): Promise { if (hashes.length > 0) { return axios - .get(`${this.apiBase}/torrents/reannounce`, { - params: { + .post( + `${this.apiBase}/torrents/reannounce`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -486,13 +533,16 @@ class ClientRequestManager { async torrentsRemoveTrackers(hash: string, urls: Array): Promise { if (urls.length > 0) { return axios - .get(`${this.apiBase}/torrents/removeTrackers`, { - params: { + .post( + `${this.apiBase}/torrents/removeTrackers`, + new URLSearchParams({ hash: hash.toLowerCase(), urls: urls.join('|'), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -502,13 +552,16 @@ class ClientRequestManager { async torrentsSetSuperSeeding(hashes: Array, value: boolean): Promise { if (hashes.length > 0) { return axios - .get(`${this.apiBase}/torrents/setSuperSeeding`, { - params: { + .post( + `${this.apiBase}/torrents/setSuperSeeding`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), value: value ? 'true' : 'false', + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -518,12 +571,15 @@ class ClientRequestManager { async torrentsToggleSequentialDownload(hashes: Array): Promise { if (hashes.length > 0) { return axios - .get(`${this.apiBase}/torrents/toggleSequentialDownload`, { - params: { + .post( + `${this.apiBase}/torrents/toggleSequentialDownload`, + new URLSearchParams({ hashes: hashes.join('|').toLowerCase(), + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing }); @@ -532,14 +588,17 @@ class ClientRequestManager { async torrentsFilePrio(hash: string, ids: Array, priority: QBittorrentTorrentContentPriority) { return axios - .get(`${this.apiBase}/torrents/filePrio`, { - params: { + .post( + `${this.apiBase}/torrents/filePrio`, + new URLSearchParams({ hash: hash.toLowerCase(), id: ids.join('|'), - priority, + priority: `${priority}`, + }), + { + headers: await this.getRequestHeaders(), }, - headers: await this.getRequestHeaders(), - }) + ) .then(() => { // returns nothing });