diff --git a/applications/tempfiles/index.js b/applications/tempfiles/index.js index ac2e7c4..3bcbd24 100644 --- a/applications/tempfiles/index.js +++ b/applications/tempfiles/index.js @@ -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) => { diff --git a/package.json b/package.json index edd4e5a..cbd2b98 100644 --- a/package.json +++ b/package.json @@ -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" } }