Updated page.getPrettyBytes() in dashboard.js and album.js to support
non-SI units (which is by 1024 instead of 1000).
With that said, all "pretty bytes" display in dashboard and
album's public pages will now use non-SI units.

Bumped v1 version string.
This commit is contained in:
Bobby Wibowo 2019-01-05 04:34:54 +07:00
parent 014936eb58
commit 8072f2fdf7
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 16 additions and 26 deletions

View File

@ -1,27 +1,22 @@
/* global LazyLoad */
const page = {
lazyLoad: null,
// byte units for getPrettyBytes()
byteUnits: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
lazyLoad: null
}
page.getPrettyBytes = function (num) {
page.getPrettyBytes = function (num, si) {
// MIT License
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
if (!Number.isFinite(num)) return num
const neg = num < 0
const neg = num < 0 ? '-' : ''
if (neg) num = -num
if (num < 1) return (neg ? '-' : '') + num + ' B'
if (num < 1) return `${neg}${num} B`
const exponent = Math.min(Math.floor(Math.log10(num) / 3), page.byteUnits.length - 1)
const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3))
const unit = page.byteUnits[exponent]
return (neg ? '-' : '') + numStr + ' ' + unit
const exponent = Math.min(Math.floor(Math.log10(num) / 3), 8) // 8 is count of KMGTPEZY
const numStr = Number((num / Math.pow(si ? 1000 : 1024, exponent)).toPrecision(3))
const pre = (si ? 'kMGTPEZY' : 'KMGTPEZY').charAt(exponent - 1) + (si ? '' : 'i')
return `${neg}${numStr} ${pre}B`
}
window.onload = function () {

View File

@ -78,9 +78,6 @@ const page = {
imageExtensions: ['.webp', '.jpg', '.jpeg', '.bmp', '.gif', '.png'],
// byte units for getPrettyBytes()
byteUnits: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
fadingIn: null
}
@ -1632,21 +1629,19 @@ page.getPrettyDate = function (date) {
date.getSeconds()
}
page.getPrettyBytes = function (num) {
page.getPrettyBytes = function (num, si) {
// MIT License
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
if (!Number.isFinite(num)) return num
const neg = num < 0
const neg = num < 0 ? '-' : ''
if (neg) num = -num
if (num < 1) return `${neg ? '-' : ''}${num}B`
if (num < 1) return `${neg}${num} B`
const exponent = Math.min(Math.floor(Math.log10(num) / 3), page.byteUnits.length - 1)
const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3))
const unit = page.byteUnits[exponent]
return `${neg ? '-' : ''}${numStr} ${unit}`
const exponent = Math.min(Math.floor(Math.log10(num) / 3), 8) // 8 is count of KMGTPEZY
const numStr = Number((num / Math.pow(si ? 1000 : 1024, exponent)).toPrecision(3))
const pre = (si ? 'kMGTPEZY' : 'KMGTPEZY').charAt(exponent - 1) + (si ? '' : 'i')
return `${neg}${numStr} ${pre}B`
}
page.getUsers = function ({ pageNum } = {}, element) {

View File

@ -15,7 +15,7 @@
v2: Images and config files (manifest.json, browserconfig.xml, etc).
v3: CSS and JS files (libs such as bulma, lazyload, etc).
#}
{% set v1 = "3f4CFlnB40" %}
{% set v1 = "kegvUlMa3q" %}
{% set v2 = "Ii3JYKIhb0" %}
{% set v3 = "3f4CFlnB40" %}