mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 09:21:32 +00:00
fix: verify database dir
This commit is contained in:
parent
6b0f03e72c
commit
f37313a84c
@ -54,21 +54,27 @@ const verify = [
|
||||
self.customPages
|
||||
]
|
||||
|
||||
self.init = async () => {
|
||||
// Check & create directories
|
||||
if (['better-sqlite3', 'sqlite3'].includes(config.database.client)) {
|
||||
verify.unshift(path.resolve('database'))
|
||||
}
|
||||
|
||||
self.initSync = () => {
|
||||
// Check & create directories (synchronous)
|
||||
for (const p of verify) {
|
||||
try {
|
||||
await self.access(p)
|
||||
fs.accessSync(p)
|
||||
} catch (err) {
|
||||
if (err.code !== 'ENOENT') {
|
||||
throw err
|
||||
} else {
|
||||
const mkdir = await self.mkdir(p)
|
||||
if (mkdir) logger.log(`Created directory: ${p}`)
|
||||
fs.mkdirSync(p)
|
||||
logger.log(`Created directory: ${p}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.purgeChunks = async () => {
|
||||
// Purge any leftover in chunks directory
|
||||
const uuidDirs = await self.readdir(self.chunks)
|
||||
await Promise.all(uuidDirs.map(async uuid => {
|
||||
@ -79,7 +85,9 @@ self.init = async () => {
|
||||
))
|
||||
await self.rmdir(root)
|
||||
}))
|
||||
if (uuidDirs.length) logger.log(`Purged ${uuidDirs.length} unfinished chunks`)
|
||||
if (uuidDirs.length) {
|
||||
logger.log(`Purged ${uuidDirs.length} unfinished chunks`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = self
|
||||
|
@ -41,6 +41,7 @@ logger.log('Starting lolisafe\u2026')
|
||||
const safe = express()
|
||||
|
||||
const paths = require('./controllers/pathsController')
|
||||
paths.initSync()
|
||||
const utils = require('./controllers/utilsController')
|
||||
|
||||
const album = require('./routes/album')
|
||||
@ -251,8 +252,8 @@ safe.use('/api', api)
|
||||
// Init database
|
||||
await require('./controllers/utils/initDatabase.js')(utils.db)
|
||||
|
||||
// Verify paths, create missing ones, clean up temp ones
|
||||
await paths.init()
|
||||
// Purge any leftover in chunks directory, do not wait
|
||||
paths.purgeChunks()
|
||||
|
||||
if (!Array.isArray(config.pages) || !config.pages.length) {
|
||||
logger.error('Config file does not have any frontend pages enabled')
|
||||
|
@ -21,7 +21,7 @@ const map = {
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
if (config.database && ['better-sqlite3', 'sqlite3'].includes(config.database.client)) {
|
||||
if (['better-sqlite3', 'sqlite3'].includes(config.database.client)) {
|
||||
try {
|
||||
await paths.access(config.database.connection.filename)
|
||||
} catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user