Maintenance commit.
This commit is contained in:
parent
651cd28698
commit
3c617239e2
@ -4,6 +4,7 @@ const path = require('path')
|
|||||||
const fsa = require('fs')
|
const fsa = require('fs')
|
||||||
const fs = fsa.promises
|
const fs = fsa.promises
|
||||||
const sqlite = require('sqlite')
|
const sqlite = require('sqlite')
|
||||||
|
const sqlite3 = require('sqlite3')
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
const URL = require('url')
|
const URL = require('url')
|
||||||
|
|
||||||
@ -29,9 +30,7 @@ function asyncForm (req, form) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function clearDatabase (config, dbPromise) {
|
async function clearDatabase (config, db) {
|
||||||
let db = await dbPromise
|
|
||||||
|
|
||||||
// Remove expired files
|
// Remove expired files
|
||||||
let files = await db.all('SELECT * FROM File WHERE upload < ?', new Date() - (config.expiry * 1000))
|
let files = await db.all('SELECT * FROM File WHERE upload < ?', new Date() - (config.expiry * 1000))
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
@ -82,11 +81,14 @@ async function init () {
|
|||||||
await fs.access(root, fsa.constants.F_OK)
|
await fs.access(root, fsa.constants.F_OK)
|
||||||
|
|
||||||
// Initialize database
|
// Initialize database
|
||||||
const dbPromise = Promise.resolve()
|
const dbPromise = sqlite.open({
|
||||||
.then(() => sqlite.open(path.join(__dirname, config.database), { Promise, cache: true }))
|
filename: path.join(__dirname, config.database),
|
||||||
.then(db => db.migrate({ migrationsPath: path.join(__dirname, 'migrations') }))
|
driver: sqlite3.cached.Database
|
||||||
|
})
|
||||||
|
|
||||||
await clearDatabase(config, dbPromise)
|
let db = await dbPromise
|
||||||
|
await db.migrate({ migrationsPath: path.join(__dirname, 'migrations') })
|
||||||
|
await clearDatabase(config, db)
|
||||||
|
|
||||||
// Upload file form
|
// Upload file form
|
||||||
router.get('/publish', (req, res, next) => {
|
router.get('/publish', (req, res, next) => {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-async-errors": "^3.1.1",
|
"express-async-errors": "^3.1.1",
|
||||||
"multiparty": "^4.2.1",
|
"multiparty": "^4.2.1",
|
||||||
"sqlite": "^3.0.3"
|
"sqlite": "^4.0.9",
|
||||||
|
"sqlite3": "^4.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user