Always use binary byte units

This commit is contained in:
Johannes Zellner
2020-06-02 14:34:38 +02:00
parent 2178dcc963
commit 589ee2d0c5
9 changed files with 35 additions and 33 deletions

View File

@@ -67,6 +67,31 @@ var ROLES = {
var SECRET_PLACEHOLDER = String.fromCharCode(0x25CF).repeat(8);
// ----------------------------------------------
// Shared Angular Filters
// ----------------------------------------------
// binary units (non SI) 1024 based
function prettyByteSize(size, fallback) {
if (!size) return fallback || 0;
var i = Math.floor(Math.log(size) / Math.log(1024));
return (size / Math.pow(1024, i)).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i];
};
angular.module('Application').filter('prettyByteSize', function () {
return function (size, fallback) { return prettyByteSize(size, fallback) || '0 kb'; }
});
angular.module('Application').filter('prettyDiskSize', function () {
return function (size, fallback) { return prettyByteSize(size, fallback) || 'Not available yet'; }
});
// ----------------------------------------------
// Cloudron REST API wrapper
// ----------------------------------------------
angular.module('Application').service('Client', ['$http', '$interval', '$timeout', 'md5', 'Notification', function ($http, $interval, $timeout, md5, Notification) {
var client = null;