diff --git a/controllers/utilsController.js b/controllers/utilsController.js index 5b30243..9b26289 100644 --- a/controllers/utilsController.js +++ b/controllers/utilsController.js @@ -549,19 +549,21 @@ self.purgeCloudflareCache = async (names, uploads, thumbs) => { return results } -self.bulkDeleteExpired = async (dryrun) => { +self.bulkDeleteExpired = async (dryrun, verbose) => { const timestamp = Date.now() / 1000 - const field = 'id' + const fields = ['id'] + if (verbose) fields.push('name') const sudo = { username: 'root' } const result = {} result.expired = await db.table('files') .where('expirydate', '<=', timestamp) - .select(field) - .then(rows => rows.map(row => row[field])) + .select(fields) if (!dryrun) { - const values = result.expired.slice() // Make a shallow copy + // Make a shallow copy + const field = fields[0] + const values = result.expired.slice().map(row => row[field]) result.failed = await self.bulkDeleteFromDb(field, values, sudo) } diff --git a/lolisafe.js b/lolisafe.js index 81c8ffa..e4884bd 100644 --- a/lolisafe.js +++ b/lolisafe.js @@ -246,8 +246,10 @@ safe.use('/api', api) logger.log('Cache control enabled without Cloudflare\'s cache purging') } - // Temporary uploads - if (Array.isArray(config.uploads.temporaryUploadAges) && config.uploads.temporaryUploadAges.length) { + // Temporary uploads (only check for expired uploads if config.uploads.temporaryUploadsInterval is also set) + if (Array.isArray(config.uploads.temporaryUploadAges) && + config.uploads.temporaryUploadAges.length && + config.uploads.temporaryUploadsInterval) { let temporaryUploadsInProgress = false const temporaryUploadCheck = async () => { if (temporaryUploadsInProgress) @@ -266,10 +268,9 @@ safe.use('/api', api) temporaryUploadsInProgress = false } - temporaryUploadCheck() - if (config.uploads.temporaryUploadsInterval) - setInterval(temporaryUploadCheck, config.uploads.temporaryUploadsInterval) + temporaryUploadCheck() + setInterval(temporaryUploadCheck, config.uploads.temporaryUploadsInterval) } // NODE_ENV=development yarn start diff --git a/scripts/delete-expired.js b/scripts/delete-expired.js index 4ade8ad..376956b 100644 --- a/scripts/delete-expired.js +++ b/scripts/delete-expired.js @@ -25,7 +25,7 @@ const self = { const dryrun = self.mode === 0 const quiet = self.mode === 2 - const result = await utils.bulkDeleteExpired(dryrun) + const result = await utils.bulkDeleteExpired(dryrun, true) if (quiet) return