Skip to content

Commit

Permalink
1.7.16-beta:
Browse files Browse the repository at this point in the history
 - Possibility to order column
 - Possibility to stop/resume a single file to be downloaded
 - Added some info in the file list (Progress, size)
  • Loading branch information
Mauro Mazzocchetti committed Oct 11, 2022
1 parent 4ec0aed commit a1f1fcd
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions routes/classes/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ const {XMLParser, XMLBuilder, XMLValidator} = require('fast-xml-parser');
const mime = require('mime-types')

const mapTorrent = (x) => {
let progress;
let lengthFile = x.files.reduce((total, file) => {
return total + file.length;
}, 0);
if (x.files && x.files.length > 0) {
progress = x.files.reduce((total, file) => {
if (file.paused) {
return total + file.length;
} else {
return total + (file.progress * file.length);
}
}, 0) / lengthFile
} else {
progress = x.progress
}
return {
size: x.files && x.files.reduce((total, file) => {
return total + file.length;
Expand All @@ -14,16 +29,11 @@ const mapTorrent = (x) => {
uploaded: x.uploaded,
downloadSpeed: x.downloadSpeed,
uploadSpeed: x.uploadSpeed,
progress: x.files && (x.files.reduce((total, file) => {
if (file.paused) {
return total + 1;
} else {
return total + file.progress;
}
}, 0)/x.files.length),
progress: progress,
ratio: x.ratio,
path: x.path,
done: x.done,
length: x.length,
paused: x.paused,
timeRemaining: x.timeRemaining,
received: x.received,
Expand Down Expand Up @@ -188,7 +198,6 @@ async function deselectFileFromTorrent(temp, db, fileName = "") {
}



async function selectFileFromTorrent(temp, db, fileName = "") {
let t = mapTorrent(temp);
let foundedTorrent;
Expand All @@ -204,7 +213,7 @@ async function selectFileFromTorrent(temp, db, fileName = "") {
if (foundedTorrent.files.find(x => f.name === x.name).paused) {
f.paused = true;
}
if(f.name === fileName) {
if (f.name === fileName) {
f.paused = false;
}
return f
Expand Down

0 comments on commit a1f1fcd

Please sign in to comment.