mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
refact: Coding standard and additional checks
* Add checks regarding `totalSize` so we don't get a division by 0 exception (Infinity more like)
This commit is contained in:
parent
1a9006c1d0
commit
f4b0c41c65
1 changed files with 24 additions and 18 deletions
|
@ -1567,33 +1567,39 @@ window.qBittorrent.DynamicTable ??= (() => {
|
||||||
}
|
}
|
||||||
const size = this.getRowValue(row, 1);
|
const size = this.getRowValue(row, 1);
|
||||||
const totalSize = this.getRowValue(row, 2);
|
const totalSize = this.getRowValue(row, 2);
|
||||||
const percent = (size / totalSize) * 100;
|
if (totalSize <= 0) {
|
||||||
if (percent === -1) {
|
|
||||||
td.textContent = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
|
td.textContent = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
|
||||||
td.title = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
|
td.title = "QBT_TR(N/A)QBT_TR[CONTEXT=TrackerListWidget]";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const percent = (size / totalSize) * 100;
|
||||||
const value = `${window.qBittorrent.Misc.toFixedPointString(percent, 2)}%`;
|
const value = `${window.qBittorrent.Misc.toFixedPointString(percent, 2)}%`;
|
||||||
td.textContent = value;
|
td.textContent = value;
|
||||||
td.title = value;
|
td.title = value;
|
||||||
};
|
};
|
||||||
this.columns["percent_selected"].compareRows = function(row1, row2) {
|
|
||||||
let percent1 = 0;
|
|
||||||
let percent2 = 0;
|
|
||||||
const hasMetadata1 = this.getRowValue(row1, 0);
|
|
||||||
if (hasMetadata1 !== false) {
|
|
||||||
const size1 = this.getRowValue(row1, 1);
|
|
||||||
const totalSize1 = this.getRowValue(row1, 2);
|
|
||||||
percent1 = (size1 / totalSize1) * 100;
|
|
||||||
}
|
|
||||||
const hasMetadata2 = this.getRowValue(row2, 0);
|
|
||||||
if (hasMetadata2 !== false) {
|
|
||||||
const size2 = this.getRowValue(row2, 1);
|
|
||||||
const totalSize2 = this.getRowValue(row2, 2);
|
|
||||||
percent2 = (size2 / totalSize2) * 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
return compareNumbers(percent1, percent2);
|
this.columns["percent_selected"].compareRows = function(row1, row2) {
|
||||||
|
const hasMetadata1 = this.getRowValue(row1, 0);
|
||||||
|
const hasMetadata2 = this.getRowValue(row2, 0);
|
||||||
|
|
||||||
|
if (hasMetadata1 === true && hasMetadata2 === false)
|
||||||
|
return -1;
|
||||||
|
if (hasMetadata1 === false && hasMetadata2 === true)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
const size1 = this.getRowValue(row1, 1);
|
||||||
|
const totalSize1 = this.getRowValue(row1, 2);
|
||||||
|
if (totalSize1 <= 0)
|
||||||
|
return 1;
|
||||||
|
const ratio1 = (size1 / totalSize1) * 100;
|
||||||
|
|
||||||
|
const size2 = this.getRowValue(row2, 1);
|
||||||
|
const totalSize2 = this.getRowValue(row2, 2);
|
||||||
|
if (totalSize2 <= 0)
|
||||||
|
return -1;
|
||||||
|
const ratio2 = (size2 / totalSize2) * 100;
|
||||||
|
|
||||||
|
return compareNumbers(ratio1, ratio2);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue