mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 16:36:21 +00:00
9e9b0d4439
Updated some dev dependencies. --- Gulp will now build CSS/JS files during development into dist-dev directory, to prevent IDE's Git from unnecessarily building diff's. Added dist-dev to ignore files. --- The entire config fille will now be passed to Nunjuck templates for ease of access of config values. Root domain for use in Nunjuck templates will now be parsed from config. Better page titles. Updated help message for "Uploads history order" option in homepage's config tab. Added "Load images for preview" option to homepage's config tab. Setting this to false will now prevent image uploads from loading themselves for previews. Uploads' original names in homepage's uploads history are now selectable. Min/max length for user/pass are now enforced in auth's front-end. Improved performance of album public pages. Their generated HTML pages will now be cached into memory. Unfortunately, No-JS version of their pages will be cached separately, so each album may take up to double the memory space. File names in thumbnails no longer have their full URLs as tooltips. I saw no point in that behavior. Added video icons. Homepage's uploads history will now display video icons for videos. "View thumbnail" button in Dashboard is now renamed to "Show preview". Their icons will also be changed depending on their file types. Added max length for albums' title & description. These will be enforced both in front-end and back-end. Existing albums that have surpassed the limits will not be enforced. A few other small improvements.
79 lines
1.8 KiB
JavaScript
79 lines
1.8 KiB
JavaScript
const { promisify } = require('util')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
const config = require('./../config')
|
|
const logger = require('./../logger')
|
|
|
|
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.dist = process.env.NODE_ENV === 'development'
|
|
? path.resolve('dist-dev')
|
|
: path.resolve('dist')
|
|
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 () => {
|
|
// Check & create directories
|
|
for (const p of verify)
|
|
try {
|
|
await self.access(p)
|
|
} catch (err) {
|
|
if (err.code !== 'ENOENT') {
|
|
throw err
|
|
} else {
|
|
const mkdir = await self.mkdir(p)
|
|
if (mkdir)
|
|
logger.log(`Created directory: ${p}`)
|
|
}
|
|
}
|
|
|
|
// Purge any leftover in 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)
|
|
}
|
|
}
|
|
|
|
module.exports = self
|