[addon] fixed file selection for multiple files on undefined index

This commit is contained in:
TheBeastLT
2020-03-17 19:19:32 +01:00
parent e06ab1ca99
commit 78b3dda9e3

View File

@@ -44,7 +44,8 @@ async function _unrestrict(apiKey, infoHash, fileIndex) {
console.log(`Retrieved torrentId: ${torrentId}`);
if (torrentId) {
const info = await RD.torrents.info(torrentId);
const targetFile = info.files.find(file => file.id === fileIndex + 1);
const targetFile = info.files.find(file => file.id === fileIndex + 1)
|| info.files.filter(file => file.selected).sort((a, b) => b.bytes - a.bytes)[0];
const selectedFiles = info.files.filter(file => file.selected);
const fileLink = info.links.length === 1
? info.links[0]