mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 00:16:21 +00:00
264bd88e88
Improved performance of /api/users/:id (admin's manage users).
Promisify fs.writeFile.
Improved performance of /api/stats.
By a lot in Linux, cause uploads size will be deferred to "du" binary.
In addition, total usage of whichever disk uploads path resides on will
also be queried using "df" binary.
Non-Linux will have to rely on manual calculation by querying DB
for each upload's size.
But logics related to uploads stats were also improved to be almost
twice as fast as before.
Improved parsing of /api/stats results on dashboard.js.
This allows ease of extending server's response by not having to update
dashboard.js by much, if at all.
Improved codes relating to item menus in dashboard's sidebar.
Finally much cleaner now 👍
No longer use /api/upload/delete API route from dashboard.
Single file deletion and bulk files deletion, both from uploads list or
by names, will now properly use a single function that will use
/api/upload/bulkdelete API route.
/api/upload/delete will still be kept indefinitely for backward support.
Fixed oddities with Select all checkbox.
Replaced all instances of modifying HTML element's style attribute with
adding/removing is-hidden CSS helper class.
Rephrased all instances of "files" to "uploads" in any display strings.
Fixed notice message when server is on private mode.
A few other improvements.
81 lines
1.8 KiB
JavaScript
81 lines
1.8 KiB
JavaScript
const { promisify } = require('util')
|
|
const config = require('./../config')
|
|
const fs = require('fs')
|
|
const logger = require('./../logger')
|
|
const path = require('path')
|
|
|
|
const self = {}
|
|
|
|
// Promisify these fs functions
|
|
const fsFuncs = [
|
|
'access',
|
|
'lstat',
|
|
'mkdir',
|
|
'readdir',
|
|
'readFile',
|
|
'rename',
|
|
'rmdir',
|
|
'symlink',
|
|
'unlink',
|
|
'writeFile'
|
|
]
|
|
|
|
for (const fsFunc of fsFuncs)
|
|
self[fsFunc] = promisify(fs[fsFunc])
|
|
|
|
self.uploads = path.resolve(config.uploads.folder)
|
|
self.chunks = path.join(self.uploads, 'chunks')
|
|
self.thumbs = path.join(self.uploads, 'thumbs')
|
|
self.zips = path.join(self.uploads, 'zips')
|
|
|
|
self.thumbPlaceholder = path.resolve(config.uploads.generateThumbs.placeholder || 'public/images/unavailable.png')
|
|
|
|
self.logs = path.resolve(config.logsFolder)
|
|
|
|
self.customPages = path.resolve('pages/custom')
|
|
self.public = path.resolve('public')
|
|
|
|
self.errorRoot = path.resolve(config.errorPages.rootDir)
|
|
|
|
const verify = [
|
|
self.uploads,
|
|
self.chunks,
|
|
self.thumbs,
|
|
self.zips,
|
|
self.logs,
|
|
self.customPages
|
|
]
|
|
|
|
self.init = async () => {
|
|
try {
|
|
for (const p of verify)
|
|
try {
|
|
await self.access(p)
|
|
} catch (err) {
|
|
if (err.code !== 'ENOENT') {
|
|
logger.error(err)
|
|
} else {
|
|
const mkdir = await self.mkdir(p)
|
|
if (mkdir)
|
|
logger.log(`Created directory: ${p}`)
|
|
}
|
|
}
|
|
|
|
// Purge chunks directory
|
|
const uuidDirs = await self.readdir(self.chunks)
|
|
for (const uuid of uuidDirs) {
|
|
const root = path.join(self.chunks, uuid)
|
|
const chunks = await self.readdir(root)
|
|
for (const chunk of chunks)
|
|
await self.unlink(path.join(root, chunk))
|
|
await self.rmdir(root)
|
|
}
|
|
|
|
self.verified = true
|
|
} catch (error) {
|
|
logger.error(error)
|
|
}
|
|
}
|
|
|
|
module.exports = self
|