mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
retry offcloud download on error
This commit is contained in:
@@ -160,7 +160,7 @@ async function _unrestrictLink(AD, torrent, encodedFileName, fileIndex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getDefaultOptions(ip) {
|
async function getDefaultOptions(ip) {
|
||||||
return { base_agent: AGENT, timeout: 5000 };
|
return { base_agent: AGENT, timeout: 10000 };
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toCommonError(error) {
|
export function toCommonError(error) {
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ async function _resolve(OC, infoHash, cachedEntryInfo, fileIndex) {
|
|||||||
} else if (torrent && statusDownloading(torrent)) {
|
} else if (torrent && statusDownloading(torrent)) {
|
||||||
console.log(`Downloading to Offcloud ${infoHash} [${fileIndex}]...`);
|
console.log(`Downloading to Offcloud ${infoHash} [${fileIndex}]...`);
|
||||||
return StaticResponse.DOWNLOADING;
|
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)}`);
|
return Promise.reject(`Failed Offcloud adding torrent ${JSON.stringify(torrent)}`);
|
||||||
@@ -124,6 +127,13 @@ async function _createTorrent(OC, infoHash) {
|
|||||||
return OC.cloud.download(magnetLink)
|
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) {
|
async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex) {
|
||||||
const targetFileName = decodeURIComponent(cachedEntryInfo);
|
const targetFileName = decodeURIComponent(cachedEntryInfo);
|
||||||
const files = await _getFileUrls(OC, torrent)
|
const files = await _getFileUrls(OC, torrent)
|
||||||
|
|||||||
Reference in New Issue
Block a user