delete error entry from TB before retrying

This commit is contained in:
TheBeastLT 2024-11-29 11:08:44 +02:00
parent 0cd3bd4d22
commit 6b693e4321

View file

@ -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);
}