1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

[shared with me] rewrote it with react (#2552)

This commit is contained in:
llj
2018-11-22 16:49:48 +08:00
committed by Daniel Pan
parent fb5d105e6e
commit fb6c097028
8 changed files with 319 additions and 4 deletions

View File

@@ -288,6 +288,38 @@ export const Utils = {
'admin': gettext("Admin"),
'cloud-edit': gettext("Preview-Edit-on-Cloud"),
'preview': gettext("Preview-on-Cloud")
},
formatSize: function(options) {
/*
* param: {bytes, precision}
*/
var bytes = options.bytes;
var precision = options.precision || 0;
var kilobyte = 1024;
var megabyte = kilobyte * 1024;
var gigabyte = megabyte * 1024;
var terabyte = gigabyte * 1024;
if ((bytes >= 0) && (bytes < kilobyte)) {
return bytes + ' B';
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
return (bytes / kilobyte).toFixed(precision) + ' KB';
} else if ((bytes >= megabyte) && (bytes < gigabyte)) {
return (bytes / megabyte).toFixed(precision) + ' MB';
} else if ((bytes >= gigabyte) && (bytes < terabyte)) {
return (bytes / gigabyte).toFixed(precision) + ' GB';
} else if (bytes >= terabyte) {
return (bytes / terabyte).toFixed(precision) + ' TB';
} else {
return bytes + ' B';
}
}
};