retry offcloud download on error

This commit is contained in:
TheBeastLT
2024-01-15 15:04:21 +02:00
parent e907953cde
commit 94ec4a7a52
2 changed files with 11 additions and 1 deletions

View File

@@ -160,7 +160,7 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
}
async function getDefaultOptions(ip) {
return { base_agent: AGENT, timeout: 5000 };
return { base_agent: AGENT, timeout: 10000 };
}
export function toCommonError(error) {

View File

@@ -101,6 +101,9 @@ async function _resolve(OC, infoHash, cachedEntryInfo, fileIndex) {
} else if (torrent && statusDownloading(torrent)) {
console.log(`Downloading to Offcloud ${infoHash} [${fileIndex}]...`);
return StaticResponse.DOWNLOADING;
} else if (torrent && statusError(torrent)) {
console.log(`Retry failed download in Offcloud ${infoHash} [${fileIndex}]...`);
return _retryCreateTorrent(OC, infoHash, cachedEntryInfo, fileIndex);
}
return Promise.reject(`Failed Offcloud adding torrent ${JSON.stringify(torrent)}`);
@@ -124,6 +127,13 @@ async function _createTorrent(OC, infoHash) {
return OC.cloud.download(magnetLink)
}
async function _retryCreateTorrent(OC, infoHash, cachedEntryInfo, fileIndex) {
const newTorrent = await _createTorrent(OC, infoHash);
return newTorrent && statusReady(newTorrent.status)
? _unrestrictLink(OC, infoHash, newTorrent, cachedEntryInfo, fileIndex)
: StaticResponse.FAILED_DOWNLOAD;
}
async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex) {
const targetFileName = decodeURIComponent(cachedEntryInfo);
const files = await _getFileUrls(OC, torrent)