mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
fix offcloud catalog meta access for single file torrents
This commit is contained in:
@@ -59,7 +59,7 @@ export async function getItemMeta(itemId, apiKey, ip) {
|
|||||||
const torrents = await OC.cloud.history();
|
const torrents = await OC.cloud.history();
|
||||||
const torrent = torrents.find(torrent => torrent.requestId === itemId)
|
const torrent = torrents.find(torrent => torrent.requestId === itemId)
|
||||||
const createDate = torrent ? new Date(torrent.createdOn) : new Date();
|
const createDate = torrent ? new Date(torrent.createdOn) : new Date();
|
||||||
return OC.cloud.explore(itemId)
|
return _getFileUrls(OC, torrent)
|
||||||
.then(files => ({
|
.then(files => ({
|
||||||
id: `${KEY}:${itemId}`,
|
id: `${KEY}:${itemId}`,
|
||||||
type: Type.OTHER,
|
type: Type.OTHER,
|
||||||
@@ -121,13 +121,7 @@ async function _createTorrent(OC, infoHash) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex) {
|
async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex) {
|
||||||
const files = await OC.cloud.explore(torrent.requestId)
|
const files = await _getFileUrls(OC, torrent)
|
||||||
.catch(error => {
|
|
||||||
if (error === 'Bad archive') {
|
|
||||||
return [`https://${torrent.server}.offcloud.com/cloud/download/${torrent.requestId}/${torrent.fileName}`];
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
})
|
|
||||||
const targetFile = Number.isInteger(fileIndex)
|
const targetFile = Number.isInteger(fileIndex)
|
||||||
? files.find(file => file.includes(`/${torrent.requestId}/${fileIndex}/`))
|
? files.find(file => file.includes(`/${torrent.requestId}/${fileIndex}/`))
|
||||||
: files.find(file => isVideo(file));
|
: files.find(file => isVideo(file));
|
||||||
@@ -139,6 +133,16 @@ async function _unrestrictLink(OC, infoHash, torrent, cachedEntryInfo, fileIndex
|
|||||||
return targetFile;
|
return targetFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function _getFileUrls(OC, torrent) {
|
||||||
|
return OC.cloud.explore(torrent.requestId)
|
||||||
|
.catch(error => {
|
||||||
|
if (error === 'Bad archive') {
|
||||||
|
return [`https://${torrent.server}.offcloud.com/cloud/download/${torrent.requestId}/${torrent.fileName}`];
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function getDefaultOptions(ip) {
|
async function getDefaultOptions(ip) {
|
||||||
return { ip, timeout: 5000 };
|
return { ip, timeout: 5000 };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user