mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 06:57:24 -06:00
WebUI: make API locale independet
Sizes are now given in bytes. Dates are Unix timestamps and converted to ISO 8601 in the web UI. Numbers are not converted to strings. -1 is returned for undefined values. Some keys have been splitted: Torrent list (json/torrents) * num_seeds: Torrent seeds connected to * num_complete: Torrent seeds in the swarm * num_leechs: Torrent leechers connected to * num_incomplete: Torrent leechers in the swarm Torrent generic properties (propertiesGeneral/hash) * total_uploaded: Total data uploaded * total_uploaded_session: Total data uploaded this session * total_downloaded: Total data dowloaded * total_downloaded_session: Total data downloaded this session * time_elapsed: Torrent elapsed time * seeding_time: Torrent elapsed time while complete * nb_connections: Torrent connection count * nb_connections_limit: Torrent connection count limit Global transfer info (json/transferInfo) * dl_info_speed: Global downalod rate * dl_info_data: Data downloaded this session * up_info_speed: Global upload rate * up_info_data: Data uploaded this session Closes #1524.
This commit is contained in:
78
src/webui/www/public/scripts/misc.js
Normal file
78
src/webui/www/public/scripts/misc.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* JS counterpart of the function in src/misc.cpp
|
||||
*/
|
||||
function friendlyUnit(value, isSpeed) {
|
||||
units = [
|
||||
"_(B)",
|
||||
"_(KiB)",
|
||||
"_(MiB)",
|
||||
"_(GiB)",
|
||||
"_(TiB)",
|
||||
];
|
||||
|
||||
if (value < 0)
|
||||
return "_(Unknown)";
|
||||
var i = 0;
|
||||
while (value >= 1024. && i++ < 6)
|
||||
value /= 1024.;
|
||||
var ret;
|
||||
if (i == 0)
|
||||
ret = value.toFixed(2) + " " + units[0];
|
||||
else
|
||||
ret = value.toFixed(2) + " " + units[i];
|
||||
if (isSpeed)
|
||||
ret += "_(/s)";
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* JS counterpart of the function in src/misc.cpp
|
||||
*/
|
||||
function friendlyDuration(seconds) {
|
||||
var MAX_ETA = 8640000;
|
||||
if (seconds < 0 || seconds >= MAX_ETA)
|
||||
return "∞";
|
||||
if (seconds == 0)
|
||||
return "0";
|
||||
if (seconds < 60)
|
||||
return "< " + "_(%1m)".replace("%1", "1"); //translation of "< 1m" not working
|
||||
var minutes = seconds / 60;
|
||||
if (minutes < 60)
|
||||
return "_(%1m)".replace("%1", parseInt(minutes));
|
||||
var hours = minutes / 60;
|
||||
minutes = minutes - hours*60;
|
||||
if (hours < 24)
|
||||
return "_(%1h %2m)".replace("%1", parseInt(hours)).replace("%2", parseInt(minutes))
|
||||
var days = hours / 24;
|
||||
hours = hours - days * 24;
|
||||
if (days < 100)
|
||||
return "_(%1d %2h)".replace("%1", parseInt(days)).replace("%2", parseInt(hours))
|
||||
return "∞";
|
||||
}
|
||||
|
||||
/*
|
||||
* From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
|
||||
*/
|
||||
if (!Date.prototype.toISOString) {
|
||||
(function() {
|
||||
|
||||
function pad(number) {
|
||||
if (number < 10) {
|
||||
return '0' + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
|
||||
Date.prototype.toISOString = function() {
|
||||
return this.getUTCFullYear() +
|
||||
'-' + pad(this.getUTCMonth() + 1) +
|
||||
'-' + pad(this.getUTCDate()) +
|
||||
'T' + pad(this.getUTCHours()) +
|
||||
':' + pad(this.getUTCMinutes()) +
|
||||
':' + pad(this.getUTCSeconds()) +
|
||||
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
|
||||
'Z';
|
||||
};
|
||||
|
||||
}());
|
||||
}
|
||||
Reference in New Issue
Block a user