From a34a4d26265dd6998b56436741f3c0b4fcaf9c08 Mon Sep 17 00:00:00 2001 From: Nano Date: Thu, 9 Sep 2021 11:53:35 +0800 Subject: [PATCH] fix(api): change param hashes to hash (#112) --- src/Api.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Api.ts b/src/Api.ts index 1d64ece..3d2accd 100644 --- a/src/Api.ts +++ b/src/Api.ts @@ -174,13 +174,7 @@ class Api { } public getTorrentTracker(hash: string) { - const params = { - hash, - }; - - return this.axios.get('/torrents/trackers', { - params, - }).then(Api.handleResponse); + return this.actionTorrent('trackers', hash); } public getTorrentPeers(hash: string, rid?: number) { @@ -195,7 +189,7 @@ class Api { } public editTracker(hash: string, origUrl: string, newUrl: string) { - return this.actionTorrents('editTracker', [hash], { origUrl, newUrl }); + return this.actionTorrent('editTracker', hash, { origUrl, newUrl }); } public setTorrentLocation(hashes: string[], location: string) { @@ -351,6 +345,15 @@ class Api { return this.axios.post('/search/enablePlugin', body).then(Api.handleResponse); } + private actionTorrent(action: string, hash: string, extra?: any) { + const params: any = { + hash, + ...extra, + }; + const data = new URLSearchParams(params); + return this.axios.post(`/torrents/${action}`, data).then(Api.handleResponse); + } + private actionTorrents(action: string, hashes: string[], extra?: any) { const params: any = { hashes: hashes.join('|'),