import $ from 'jquery'
// https://stackoverflow.com/a/18650828
function formatBytes (a, b) {
if (a === 0) return '0 Bytes'
const c = 1024
const d = b || 2
const e = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const f = Math.floor(Math.log(a) / Math.log(c))
return parseFloat((a / Math.pow(c, f)).toFixed(d)) + ' ' + e[f]
}
function recursiveStats (table, subtable) {
for (const key in table) {
let val = table[key]
if (typeof val === 'object') {
recursiveStats(val, key)
} else {
if (key === 'time') {
const date = new Date(null)
date.setSeconds(Math.floor(parseInt(val) / 1000)) // specify value for SECONDS here
val = date.toISOString().substr(11, 8)
} else if (key.indexOf('bytes') !== -1) {
val = formatBytes(val, 3)
}
$('#stat_' + (subtable ? subtable + '_' : '') + key).text(val)
}
}
}
function updateLinkList (k) {
if (k && k.error) return alert(k.error)
$.get('/dashboard/link', function (res) {
if (res.error) return
$('#link-list').html('
')
$('#link-list tbody').append('
Name
URL
Action
')
for (const i in res) {
const p = res[i]
p.name = p.name.replace(/\/g, '>')
$('#link-list tbody').append('