From 6b693e432176a2f96d75de2491fada91d6a506dd Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Fri, 29 Nov 2024 11:08:44 +0200 Subject: [PATCH] delete error entry from TB before retrying --- addon/moch/torbox.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addon/moch/torbox.js b/addon/moch/torbox.js index 5462d27..1cd4e6c 100644 --- a/addon/moch/torbox.js +++ b/addon/moch/torbox.js @@ -100,7 +100,8 @@ async function _resolve(apiKey, infoHash, cachedEntryInfo, fileIndex, ip) { return StaticResponse.DOWNLOADING; } else if (torrent && statusError(torrent)) { console.log(`Retry failed download in TorBox ${infoHash} [${fileIndex}]...`); - return _retryCreateTorrent(apiKey, infoHash, cachedEntryInfo, fileIndex); + return controlTorrent(apiKey, torrent.id, 'delete') + .then(() => _retryCreateTorrent(apiKey, infoHash, cachedEntryInfo, fileIndex)); } return Promise.reject(`Failed TorBox adding torrent ${JSON.stringify(torrent)}`); @@ -188,6 +189,20 @@ async function createTorrent(apiKey, magnetLink){ .catch(error => Promise.reject(error.response?.data || error)); } +async function controlTorrent(apiKey, torrent_id, operation){ + const url = `${baseUrl}/api/torrents/controltorrent` + const headers = getHeaders(apiKey); + const data = { torrent_id, operation} + return axios.post(url, data, { headers, timeout }) + .then(response => { + if (response.data?.success) { + return Promise.resolve(response.data.data); + } + return Promise.reject(response.data); + }) + .catch(error => Promise.reject(error.response?.data || error)); +} + async function getTorrentList(apiKey, id = undefined, offset = 0) { return getItemList(apiKey, 'torrents', id, offset); }