mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Upgraded Filesize.js to 2.0.0
Fixed: File size/disk space in UI now shows actual size instead of manufacturer size (111 GB instead of 120 GB)
This commit is contained in:
parent
149f94b006
commit
c3bd5e0053
@ -6,64 +6,41 @@
|
||||
* @license BSD-3 <https://raw.github.com/avoidwork/filesize.js/master/LICENSE>
|
||||
* @link http://filesizejs.com
|
||||
* @module filesize
|
||||
* @version 1.10.0
|
||||
* @version 2.0.0
|
||||
*/
|
||||
( function ( global ) {
|
||||
"use strict";
|
||||
"use strict";
|
||||
|
||||
var base = 10,
|
||||
right = /\.(.*)/,
|
||||
bit = /b$/,
|
||||
var bit = /b$/,
|
||||
bite = /^B$/,
|
||||
zero = /^0$/,
|
||||
options;
|
||||
radix = 10,
|
||||
right = /\.(.*)/,
|
||||
zero = /^0$/;
|
||||
|
||||
options = {
|
||||
all : {
|
||||
increments : [["B", 1], ["kb", 125], ["kB", 1000], ["Mb", 125000], ["MB", 1000000], ["Gb", 125000000], ["GB", 1000000000], ["Tb", 125000000000], ["TB", 1000000000000], ["Pb", 125000000000000], ["PB", 1000000000000000]],
|
||||
nth : 11
|
||||
},
|
||||
bitless : {
|
||||
increments : [["B", 1], ["kB", 1000], ["MB", 1000000], ["GB", 1000000000], ["TB", 1000000000000], ["PB", 1000000000000000]],
|
||||
nth : 6
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
/**
|
||||
* filesize
|
||||
*
|
||||
* @method filesize
|
||||
* @param {Mixed} arg String, Int or Float to transform
|
||||
* @param {Mixed} pos [Optional] Position to round to, defaults to 2 if shrt is ommitted, or `true` for shrthand output
|
||||
* @param {Boolean} bits [Optional] Determines if `bit` sizes are used for result calculation, default is true
|
||||
* @param {Object} descriptor [Optional] Flags
|
||||
* @return {String} Readable file size String
|
||||
*/
|
||||
function filesize ( arg) {
|
||||
function filesize ( arg, descriptor ) {
|
||||
var result = "",
|
||||
bits = true,
|
||||
skip = false,
|
||||
i, neg, num, pos, shrt, size, sizes, suffix, z;
|
||||
i = 6,
|
||||
base, bits, neg, num, round, size, sizes, unix, spacer, suffix, z;
|
||||
|
||||
// Determining arguments
|
||||
if (arguments[3] !== undefined) {
|
||||
pos = arguments[1];
|
||||
shrt = arguments[2];
|
||||
bits = arguments[3];
|
||||
}
|
||||
else {
|
||||
typeof arguments[1] === "boolean" ? shrt = arguments[1] : pos = arguments[1];
|
||||
|
||||
if ( typeof arguments[2] === "boolean" ) {
|
||||
bits = arguments[2];
|
||||
}
|
||||
if ( isNaN( arg ) ) {
|
||||
throw new Error( "Invalid arguments" );
|
||||
}
|
||||
|
||||
if ( isNaN( arg ) || ( pos !== undefined && isNaN( pos ) ) ) {
|
||||
throw new Error("Invalid arguments");
|
||||
}
|
||||
|
||||
shrt = ( shrt === true );
|
||||
bits = ( bits === true );
|
||||
pos = shrt ? 1 : ( pos === undefined ? 2 : parseInt( pos, base ) );
|
||||
descriptor = descriptor || {};
|
||||
bits = ( descriptor.bits === true );
|
||||
unix = ( descriptor.unix === true );
|
||||
base = descriptor.base !== undefined ? descriptor.base : unix ? 2 : 10;
|
||||
round = descriptor.round !== undefined ? descriptor.round : unix ? 1 : 2;
|
||||
spacer = descriptor.spacer !== undefined ? descriptor.spacer : unix ? "" : " ";
|
||||
num = Number( arg );
|
||||
neg = ( num < 0 );
|
||||
|
||||
@ -74,22 +51,15 @@
|
||||
|
||||
// Zero is now a special case because bytes divide by 1
|
||||
if ( num === 0 ) {
|
||||
if ( shrt ) {
|
||||
if ( unix ) {
|
||||
result = "0";
|
||||
}
|
||||
else {
|
||||
result = "0 B";
|
||||
result = "0" + spacer + "B";
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( bits ) {
|
||||
sizes = options.all.increments;
|
||||
i = options.all.nth;
|
||||
}
|
||||
else {
|
||||
sizes = options.bitless.increments;
|
||||
i = options.bitless.nth;
|
||||
}
|
||||
sizes = options[base][bits ? "bits" : "bytes"];
|
||||
|
||||
while ( i-- ) {
|
||||
size = sizes[i][1];
|
||||
@ -99,12 +69,12 @@
|
||||
// Treating bytes as cardinal
|
||||
if ( bite.test( suffix ) ) {
|
||||
skip = true;
|
||||
pos = 0;
|
||||
round = 0;
|
||||
}
|
||||
|
||||
result = ( num / size ).toFixed( pos );
|
||||
result = ( num / size ).toFixed( round );
|
||||
|
||||
if ( !skip && shrt ) {
|
||||
if ( !skip && unix ) {
|
||||
if ( bits && bit.test( suffix ) ) {
|
||||
suffix = suffix.toLowerCase();
|
||||
}
|
||||
@ -112,19 +82,20 @@
|
||||
suffix = suffix.charAt( 0 );
|
||||
z = right.exec( result );
|
||||
|
||||
if ( suffix === "k" ) {
|
||||
if ( !bits && suffix === "k" ) {
|
||||
suffix = "K";
|
||||
}
|
||||
|
||||
if ( z !== null && z[1] !== undefined && zero.test( z[1] ) ) {
|
||||
result = parseInt( result, base );
|
||||
result = parseInt( result, radix );
|
||||
}
|
||||
|
||||
result += suffix;
|
||||
result += spacer + suffix;
|
||||
}
|
||||
else if ( !shrt ) {
|
||||
result += " " + suffix;
|
||||
else if ( !unix ) {
|
||||
result += spacer + suffix;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -136,18 +107,35 @@
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// CommonJS, AMD, script tag
|
||||
if ( typeof exports !== "undefined" ) {
|
||||
module.exports = filesize;
|
||||
/**
|
||||
* Size options
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
var options = {
|
||||
2 : {
|
||||
bits : [["B", 1], ["kb", 128], ["Mb", 131072], ["Gb", 134217728], ["Tb", 137438953472], ["Pb", 140737488355328]],
|
||||
bytes : [["B", 1], ["kB", 1024], ["MB", 1048576], ["GB", 1073741824], ["TB", 1099511627776], ["PB", 1125899906842624]]
|
||||
},
|
||||
10 : {
|
||||
bits : [["B", 1], ["kb", 125], ["Mb", 125000], ["Gb", 125000000], ["Tb", 125000000000], ["Pb", 125000000000000]],
|
||||
bytes : [["B", 1], ["kB", 1000], ["MB", 1000000], ["GB", 1000000000], ["TB", 1000000000000], ["PB", 1000000000000000]]
|
||||
}
|
||||
else if ( typeof define === "function" ) {
|
||||
};
|
||||
|
||||
// CommonJS, AMD, script tag
|
||||
if ( typeof exports !== "undefined" ) {
|
||||
module.exports = filesize;
|
||||
}
|
||||
else if ( typeof define === "function" ) {
|
||||
define( function () {
|
||||
return filesize;
|
||||
});
|
||||
}
|
||||
else {
|
||||
} );
|
||||
}
|
||||
else {
|
||||
global.filesize = filesize;
|
||||
}
|
||||
})( this );
|
||||
}
|
||||
|
||||
} )( this );
|
||||
|
@ -10,7 +10,7 @@ define(
|
||||
|
||||
bytes: function (sourceSize) {
|
||||
var size = Number(sourceSize);
|
||||
return Filesize(size, 1, false);
|
||||
return Filesize(size, { base: 2, round: 1 });
|
||||
},
|
||||
|
||||
dateHelper: function (sourceDate) {
|
||||
|
Loading…
Reference in New Issue
Block a user