Maintenance commit.

This commit is contained in:
Evert Prants 2020-05-28 22:47:06 +03:00
parent 651cd28698
commit 3c617239e2
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 11 additions and 8 deletions

View File

@ -4,6 +4,7 @@ const path = require('path')
const fsa = require('fs')
const fs = fsa.promises
const sqlite = require('sqlite')
const sqlite3 = require('sqlite3')
const crypto = require('crypto')
const URL = require('url')
@ -29,9 +30,7 @@ function asyncForm (req, form) {
})
}
async function clearDatabase (config, dbPromise) {
let db = await dbPromise
async function clearDatabase (config, db) {
// Remove expired files
let files = await db.all('SELECT * FROM File WHERE upload < ?', new Date() - (config.expiry * 1000))
if (files.length > 0) {
@ -82,11 +81,14 @@ async function init () {
await fs.access(root, fsa.constants.F_OK)
// Initialize database
const dbPromise = Promise.resolve()
.then(() => sqlite.open(path.join(__dirname, config.database), { Promise, cache: true }))
.then(db => db.migrate({ migrationsPath: path.join(__dirname, 'migrations') }))
const dbPromise = sqlite.open({
filename: path.join(__dirname, config.database),
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
router.get('/publish', (req, res, next) => {

View File

@ -14,6 +14,7 @@
"express": "^4.17.1",
"express-async-errors": "^3.1.1",
"multiparty": "^4.2.1",
"sqlite": "^3.0.3"
"sqlite": "^4.0.9",
"sqlite3": "^4.2.0"
}
}