diff --git a/client/app/components/admin/TorrentTable.jsx b/client/app/components/admin/TorrentTable.jsx index 4cb56fd..3f06ed3 100644 --- a/client/app/components/admin/TorrentTable.jsx +++ b/client/app/components/admin/TorrentTable.jsx @@ -38,7 +38,8 @@ class TorrentTable extends Component { // Link to repo: https://github.com/sindresorhus/pretty-bytes convertSizeToHumanSize(num) { if (!Number.isFinite(num)) { - throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`); + return num + // throw new TypeError(`Expected a finite number, got ${typeof num}: ${num}`); } const neg = num < 0; @@ -57,6 +58,17 @@ class TorrentTable extends Component { return (neg ? '-' : '') + numStr + ' ' + unit; } + convertHumanSizeToBytes(string) { + const [numStr, unit] = string.split(' '); + if (this.UNITS.indexOf(unit) === -1) { + return string + } + + const exponent = this.UNITS.indexOf(unit) * 3 + + return numStr * (Math.pow(10, exponent)) + } + sendToDownload(magnet) { const apiData = { magnet: magnet, @@ -80,8 +92,6 @@ class TorrentTable extends Component { return item }) - console.log(filteredByQuery) - this.setState({ torrentResponse: filteredByQuery, filterQuery: query, @@ -101,6 +111,9 @@ class TorrentTable extends Component { let valueA = isNaN(a[col]) ? a[col] : parseInt(a[col]) let valueB = isNaN(b[col]) ? b[col] : parseInt(b[col]) + valueA = (col == 'size') ? this.convertHumanSizeToBytes(valueA) : valueA + valueB = (col == 'size') ? this.convertHumanSizeToBytes(valueB) : valueB + if (direction) return valueAvalueB?-1:0; else @@ -193,4 +206,4 @@ class TorrentTable extends Component { } } -export default TorrentTable; \ No newline at end of file +export default TorrentTable;