From ef48da6478a5386eea4cdc762c83429ca76887fa Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Mon, 6 Jan 2020 23:10:21 +0200 Subject: [PATCH] shortened urls cleanup --- applications/tempfiles/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/applications/tempfiles/index.js b/applications/tempfiles/index.js index a6716ea..31e43fa 100644 --- a/applications/tempfiles/index.js +++ b/applications/tempfiles/index.js @@ -52,7 +52,16 @@ async function clearDatabase (config, dbPromise) { } } - console.log('Database was cleared of %d files and %d IPFS hashes.', files.length, hashes.length) + // Shortened URLs + let shorts = await db.all('SELECT hash FROM Short WHERE timeat < ?', new Date() - (config.expiry * 1000)) + if (shorts.length > 0) { + for (let i in shorts) { + await db.run('DELETE FROM Short WHERE hash = ?', shorts[i].hash) + } + } + + console.log('Database was cleared of %d files, %d IPFS hashes and %d shortened URLs.', + files.length, hashes.length, shorts.length) } async function init () {