-
Notifications
You must be signed in to change notification settings - Fork 2
/
scripts.js
106 lines (97 loc) · 3.18 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function secondsToHms(d) {
d = Number(d);
const h = Math.floor(d / 3600);
const m = Math.floor(d % 3600 / 60);
const s = Math.floor(d % 3600 % 60);
const hDisplay = h > 0 ? h + (h == 1 ? " hour " : " hours ") : "";
const mDisplay = m > 0 ? m + (m == 1 ? " minute " : " minutes ") : "";
const sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
return hDisplay + mDisplay + sDisplay;
}
function formatBytes(bytes, decimals = 2) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
$(() => {
let offset = 0;
const limit = 20;
let dl_url;
const load = () => {
const url = '/list';
const qry = {
backward: 1,
count: limit,
property: 'Normal',
from: offset,
action: 'dir',
format: 'all'
};
$.getJSON(url + '?' + $.param(qry)).then(function(res) {
if (!res) {
$('#btn-more').hide();
return;
}
if (!res.Normal) {
$('#btn-more').hide();
return;
}
if (!res.Normal.file) {
$('#btn-more').hide();
return;
}
offset += res.Normal.file.length;
if (res.Normal.file.length < limit) {
$('#btn-more').hide();
};
dl_url = res.URL;
$('#table').bootstrapTable('append', res.Normal.file);
});
};
$('#table').bootstrapTable({
columns: [{
field: 'name',
title: 'Name',
formatter: (value, row, index) => {
const nl = value.split("/");
const justname = nl[nl.length-1] ;
const relapth = value.startsWith('/') ? value.substr(1) : value;
let width,height;
[width,height] = row["format"]["@size"].split("x") ;
return `<a href="/show?path=${value}&width=${width}&height=${height}" target="_blank">${justname}</a>`+
` [<a href="${dl_url}${relapth}">\u21E9</a>]`;
}
}, {
field: 'time',
title: 'Date',
formatter: (value, row, index) => {
return value.split(" ")[0];
}
}, {
field: 'time',
title: 'Time',
formatter: (value, row, index) => {
return value.split(" ")[1];
}
}, {
field: 'size',
title: 'Size',
formatter: (value, row, index) => {
return formatBytes(value,2);
}
},{
field: 'format.@time',
title: 'Duration',
formatter: (value, row, index) => {
return secondsToHms(Math.round(parseFloat(value)));
}
}]
});
$('#btn-more').click(() => {
load();
});
load();
});