Better 'df' handling (check the TODO entry for more details).

Simplified a few lines in dashboard.js.

Bumped v1 version string.
This commit is contained in:
Bobby Wibowo 2019-11-14 05:06:59 +07:00
parent d5cd5b7b5b
commit 3d09df501d
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
6 changed files with 52 additions and 15 deletions

View File

@ -6,7 +6,7 @@ Normal priority:
* [x] Use [native lazy-load tag](https://web.dev/native-lazy-loading) on nojs album pages.
* [x] Use incremental version numbering instead of randomized strings.
* [ ] Use versioning in /api/check. To elaborate, make it so that when a version string reported by server is higher than expected, force user to reload the page (which should be all that is needed for users to be loading latest front-end assets). Possibly also use it in /api/tokens/verify, for dashboard page.
* [ ] Better `df` handling (system disk stats). To elaborate, either properly show disk usages of directories that have sub-directories, or only show disk usages of whitelisted directories (thumbs, chunks, etc).
* [x] Better `df` handling (system disk stats). To elaborate, either properly show disk usages of directories that have sub-directories, or only show disk usages of whitelisted directories (thumbs, chunks, etc).
* [x] Use loading spinners on dashboard's sidebar menus.
* [x] Disable all other sidebar menus when a menu is still loading.
* [ ] Collapsible dashboard's sidebar albums menus.

View File

@ -579,20 +579,22 @@ self.stats = async (req, res, next) => {
} else {
statsCache.disk.generating = true
// We pre-assign the keys below to guarantee their order
stats.disk = {
_types: {
byte: ['uploads', 'thumbs', 'zips', 'chunks'],
byteUsage: ['drive']
},
drive: null,
// We pre-assign the keys below to fix their order
uploads: 0,
thumbs: 0,
zips: 0,
chunks: 0
}
// Get size of directories in uploads path
const subdirs = []
// Get size of uploads path (excluding sub-directories)
await new Promise((resolve, reject) => {
const proc = spawn('du', [
'--apparent-size',
@ -607,14 +609,17 @@ self.stats = async (req, res, next) => {
const formatted = String(data)
.trim()
.split(/\s+/)
if (formatted.length !== 2) return
for (let i = 0; i < formatted.length; i += 2) {
const path = formatted[i + 1]
if (!path) return
const basename = path.basename(formatted[1])
stats.disk[basename] = parseInt(formatted[0])
if (path !== paths.uploads) {
subdirs.push(path)
continue
}
// Add to types if necessary
if (!stats.disk._types.byte.includes(basename))
stats.disk._types.byte.push(basename)
stats.disk.uploads = parseInt(formatted[i])
}
})
const stderr = []
@ -626,6 +631,40 @@ self.stats = async (req, res, next) => {
})
})
await Promise.all(subdirs.map(subdir => {
return new Promise((resolve, reject) => {
const proc = spawn('du', [
'--apparent-size',
'--block-size=1',
'--dereference',
'--summarize',
subdir
])
proc.stdout.on('data', data => {
const formatted = String(data)
.trim()
.split(/\s+/)
if (formatted.length !== 2) return
const basename = path.basename(formatted[1])
stats.disk[basename] = parseInt(formatted[0])
// Add to types if necessary
if (!stats.disk._types.byte.includes(basename))
stats.disk._types.byte.push(basename)
})
const stderr = []
proc.stderr.on('data', data => stderr.push(data))
proc.on('exit', code => {
if (code !== 0) return reject(stderr)
resolve()
})
})
}))
// Get disk usage of whichever disk uploads path resides on
await new Promise((resolve, reject) => {
const proc = spawn('df', [

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -353,8 +353,6 @@ page.fadeAndScroll = disableFading => {
page.dom.classList.remove('fade-in')
}
const behavior = disableFading ? 'auto' : 'smooth'
if (!disableFading) {
page.dom.classList.add('fade-in')
page.fadingIn = setTimeout(() => {
@ -363,7 +361,7 @@ page.fadeAndScroll = disableFading => {
}
page.dom.scrollIntoView({
behavior,
behavior: disableFading ? 'auto' : 'smooth',
block: 'start',
inline: 'nearest'
})

View File

@ -1,5 +1,5 @@
{
"1": "1573625966",
"1": "1573682741",
"2": "1568894058",
"3": "1568894058",
"4": "1568894058",