mirror of
https://github.com/transmission/transmission
synced 2025-03-03 18:25:35 +00:00
Fix display of size values in web interface (#2703)
* Fix display of size values in web interface: The web interface rounded large number values down using Math.floor(), causing the web interface to display faulty torrent/download sizes. A torrent of size 1,92 GB (915 pieces @ 2,1 MB) was shown as "1GB". After about half the download was done, the UI showed "1GB of 1GB (55%)", which is rather irritating. The fix removes the `Math.floor()` and adds fractions to the larger size values.
This commit is contained in:
parent
abfd47a4a8
commit
cc7d1c5f01
2 changed files with 34 additions and 8 deletions
2
web/public_html/transmission-app.js
generated
2
web/public_html/transmission-app.js
generated
File diff suppressed because one or more lines are too long
|
@ -9,19 +9,45 @@ const number_format = new Intl.NumberFormat(current_locale);
|
|||
|
||||
const kilo = 1000;
|
||||
const mem_formatters = [
|
||||
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'byte' }),
|
||||
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'kilobyte' }),
|
||||
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'megabyte' }),
|
||||
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'gigabyte' }),
|
||||
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'terabyte' }),
|
||||
new Intl.NumberFormat(current_locale, { style: 'unit', unit: 'petabyte' }),
|
||||
new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 0,
|
||||
style: 'unit',
|
||||
unit: 'byte',
|
||||
}),
|
||||
new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 0,
|
||||
style: 'unit',
|
||||
unit: 'kilobyte',
|
||||
}),
|
||||
new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 0,
|
||||
style: 'unit',
|
||||
unit: 'megabyte',
|
||||
}),
|
||||
new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 2,
|
||||
style: 'unit',
|
||||
unit: 'gigabyte',
|
||||
}),
|
||||
new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 2,
|
||||
style: 'unit',
|
||||
unit: 'terabyte',
|
||||
}),
|
||||
new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 2,
|
||||
style: 'unit',
|
||||
unit: 'petabyte',
|
||||
}),
|
||||
];
|
||||
|
||||
const fmt_kBps = new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 2,
|
||||
style: 'unit',
|
||||
unit: 'kilobyte-per-second',
|
||||
});
|
||||
const fmt_MBps = new Intl.NumberFormat(current_locale, {
|
||||
maximumFractionDigits: 2,
|
||||
style: 'unit',
|
||||
unit: 'megabyte-per-second',
|
||||
});
|
||||
|
@ -51,7 +77,7 @@ export const Formatter = {
|
|||
let size = bytes;
|
||||
for (const nf of mem_formatters) {
|
||||
if (size < kilo) {
|
||||
return nf.format(Math.floor(size));
|
||||
return nf.format(size);
|
||||
}
|
||||
size /= kilo;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue