remove availability check for DL

This commit is contained in:
TheBeastLT 2024-11-26 09:28:32 +02:00
parent 12c608a51d
commit 655f17901c

View file

@ -3,31 +3,16 @@ import { Type } from '../lib/types.js';
import { isVideo, isArchive } from '../lib/extension.js'; import { isVideo, isArchive } from '../lib/extension.js';
import StaticResponse from './static.js'; import StaticResponse from './static.js';
import { getMagnetLink } from '../lib/magnetHelper.js'; import { getMagnetLink } from '../lib/magnetHelper.js';
import { chunkArray, BadTokenError } from './mochHelper.js'; import { BadTokenError } from './mochHelper.js';
const KEY = 'debridlink'; const KEY = 'debridlink';
export async function getCachedStreams(streams, apiKey) { export async function getCachedStreams(streams, apiKey) {
const options = await getDefaultOptions(); return streams
const DL = new DebridLinkClient(apiKey, options);
const hashBatches = chunkArray(streams.map(stream => stream.infoHash), 50)
.map(batch => batch.join(','));
const available = await Promise.all(hashBatches.map(hashes => DL.seedbox.cached(hashes)))
.then(results => results.map(result => result.value))
.then(results => results.reduce((all, result) => Object.assign(all, result), {}))
.catch(error => {
if (toCommonError(error)) {
return Promise.reject(error);
}
console.warn('Failed DebridLink cached torrent availability request:', error);
return undefined;
});
return available && streams
.reduce((mochStreams, stream) => { .reduce((mochStreams, stream) => {
const cachedEntry = available[stream.infoHash];
mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = { mochStreams[`${stream.infoHash}@${stream.fileIdx}`] = {
url: `${apiKey}/${stream.infoHash}/null/${stream.fileIdx}`, url: `${apiKey}/${stream.infoHash}/null/${stream.fileIdx}`,
cached: !!cachedEntry cached: false
}; };
return mochStreams; return mochStreams;
}, {}) }, {})