Updated album.js and dashboard.js

Updated getPrettyBytes() function.
Previously it was doing something wrong with size under 1024 bytes.
This commit is contained in:
Bobby Wibowo 2019-01-14 20:06:57 +07:00
parent fe24198517
commit f2a6daea46
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 34 additions and 32 deletions

View File

@ -10,11 +10,12 @@ page.getPrettyBytes = function (num, si) {
if (!Number.isFinite(num)) return num
const neg = num < 0 ? '-' : ''
const scale = si ? 1000 : 1024
if (neg) num = -num
if (num < 1) return `${neg}${num} B`
if (num < scale) return `${neg}${num} B`
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 numStr = Number((num / Math.pow(scale, exponent)).toPrecision(3))
const pre = (si ? 'kMGTPEZY' : 'KMGTPEZY').charAt(exponent - 1) + (si ? '' : 'i')
return `${neg}${numStr} ${pre}B`
}

View File

@ -1603,35 +1603,6 @@ page.setActiveMenu = function (activeItem) {
activeItem.classList.add('is-active')
}
page.getPrettyDate = function (date) {
return date.getFullYear() + '-' +
(date.getMonth() < 9 ? '0' : '') + // month's index starts from zero
(date.getMonth() + 1) + '-' +
(date.getDate() < 10 ? '0' : '') +
date.getDate() + ' ' +
(date.getHours() < 10 ? '0' : '') +
date.getHours() + ':' +
(date.getMinutes() < 10 ? '0' : '') +
date.getMinutes() + ':' +
(date.getSeconds() < 10 ? '0' : '') +
date.getSeconds()
}
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 ? '-' : ''
if (neg) num = -num
if (num < 1) return `${neg}${num} B`
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) {
if (element) page.isLoading(element, true)
if (pageNum === undefined) pageNum = 0
@ -1997,6 +1968,36 @@ page.paginate = function (totalItems, itemsPerPage, currentPage) {
`
}
page.getPrettyDate = function (date) {
return date.getFullYear() + '-' +
(date.getMonth() < 9 ? '0' : '') + // month's index starts from zero
(date.getMonth() + 1) + '-' +
(date.getDate() < 10 ? '0' : '') +
date.getDate() + ' ' +
(date.getHours() < 10 ? '0' : '') +
date.getHours() + ':' +
(date.getMinutes() < 10 ? '0' : '') +
date.getMinutes() + ':' +
(date.getSeconds() < 10 ? '0' : '') +
date.getSeconds()
}
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 scale = si ? 1000 : 1024
if (neg) num = -num
if (num < scale) return `${neg}${num} B`
const exponent = Math.min(Math.floor(Math.log10(num) / 3), 8) // 8 is count of KMGTPEZY
const numStr = Number((num / Math.pow(scale, exponent)).toPrecision(3))
const pre = (si ? 'kMGTPEZY' : 'KMGTPEZY').charAt(exponent - 1) + (si ? '' : 'i')
return `${neg}${numStr} ${pre}B`
}
window.onload = function () {
// Add 'no-touch' class to non-touch devices
if (!('ontouchstart' in document.documentElement))

View File

@ -16,7 +16,7 @@
v3: CSS and JS files (libs such as bulma, lazyload, etc).
v4: Renders in /public/render/* directories (to be used by render.js).
#}
{% set v1 = "2blVrmMr6P" %}
{% set v1 = "ihtjxiY8oB" %}
{% set v2 = "hiboQUzAzp" %}
{% set v3 = "hiboQUzAzp" %}
{% set v4 = "dLp5zKKIkN" %}