No longer initiate expired uploads check if
config.uploads.temporaryUploadsInterval is not set.

"yarn delete-expired" will now list names of the expired uploads too.
This commit is contained in:
Bobby Wibowo 2020-05-16 21:45:14 +07:00
parent be7437d673
commit 968fd74676
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
3 changed files with 14 additions and 11 deletions

View File

@ -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)
}

View File

@ -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,9 +268,8 @@ safe.use('/api', api)
temporaryUploadsInProgress = false
}
temporaryUploadCheck()
if (config.uploads.temporaryUploadsInterval)
temporaryUploadCheck()
setInterval(temporaryUploadCheck, config.uploads.temporaryUploadsInterval)
}

View File

@ -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