Updated albumsController.js

Trying to purge empty albums (purge = also deleting all of the files associated with it) will no longer throw out warning about failing to delete any of the associated files (since there are supposed to be none for empty albums anyways).
This commit is contained in:
Bobby Wibowo 2018-07-14 11:00:10 +07:00
parent 4d7b23bb39
commit ff3a6d1fb0
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF

View File

@ -138,7 +138,6 @@ albumsController.delete = async (req, res, next) => {
return res.json({ success: false, description: 'No album specified.' })
}
let ids = []
let failed = []
if (purge) {
const files = await db.table('files')
@ -147,11 +146,13 @@ albumsController.delete = async (req, res, next) => {
userid: user.id
})
ids = files.map(file => file.id)
failed = await utils.bulkDeleteFiles('id', ids, user)
if (files.length) {
const ids = files.map(file => file.id)
failed = await utils.bulkDeleteFiles('id', ids, user)
if (failed.length === ids.length) {
return res.json({ success: false, description: 'Could not delete any of the files associated with the album.' })
if (failed.length === ids.length) {
return res.json({ success: false, description: 'Could not delete any of the files associated with the album.' })
}
}
}