mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-19 01:31:34 +00:00
fix: delete album only worked for own albums
This commit is contained in:
parent
dbc0a82186
commit
30b8f0040c
@ -246,16 +246,37 @@ self.disable = async (req, res, next) => {
|
|||||||
|
|
||||||
const ismoderator = perms.is(user, 'moderator')
|
const ismoderator = perms.is(user, 'moderator')
|
||||||
|
|
||||||
const id = req.body.id
|
const id = parseInt(req.body.id)
|
||||||
|
if (isNaN(id)) throw new ClientError('No album specified.')
|
||||||
|
|
||||||
const purge = req.body.purge
|
const purge = req.body.purge
|
||||||
const del = ismoderator ? req.body.del : false
|
const del = ismoderator ? req.body.del : false
|
||||||
if (!Number.isFinite(id)) throw new ClientError('No album specified.')
|
|
||||||
|
const filter = function () {
|
||||||
|
this.where('id', id)
|
||||||
|
|
||||||
|
if (!ismoderator) {
|
||||||
|
this.andWhere({
|
||||||
|
enabled: 1,
|
||||||
|
userid: user.id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const album = await db.table('albums')
|
||||||
|
.where(filter)
|
||||||
|
.first()
|
||||||
|
|
||||||
|
if (!album) {
|
||||||
|
throw new ClientError('Could not get album with the specified ID.')
|
||||||
|
}
|
||||||
|
logger.inspect(album)
|
||||||
|
|
||||||
if (purge) {
|
if (purge) {
|
||||||
const files = await db.table('files')
|
const files = await db.table('files')
|
||||||
.where({
|
.where({
|
||||||
albumid: id,
|
albumid: id,
|
||||||
userid: user.id
|
userid: album.userid
|
||||||
})
|
})
|
||||||
|
|
||||||
if (files.length) {
|
if (files.length) {
|
||||||
@ -266,16 +287,6 @@ self.disable = async (req, res, next) => {
|
|||||||
utils.invalidateStatsCache('uploads')
|
utils.invalidateStatsCache('uploads')
|
||||||
}
|
}
|
||||||
|
|
||||||
const filter = {
|
|
||||||
id,
|
|
||||||
userid: user.id
|
|
||||||
}
|
|
||||||
const identifier = await db.table('albums')
|
|
||||||
.select('identifier')
|
|
||||||
.where(filter)
|
|
||||||
.first()
|
|
||||||
.then(row => row.identifier)
|
|
||||||
|
|
||||||
if (del) {
|
if (del) {
|
||||||
await db.table('albums')
|
await db.table('albums')
|
||||||
.where(filter)
|
.where(filter)
|
||||||
@ -291,7 +302,7 @@ self.disable = async (req, res, next) => {
|
|||||||
utils.invalidateStatsCache('albums')
|
utils.invalidateStatsCache('albums')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await paths.unlink(path.join(paths.zips, `${identifier}.zip`))
|
await paths.unlink(path.join(paths.zips, `${album.identifier}.zip`))
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Re-throw non-ENOENT error
|
// Re-throw non-ENOENT error
|
||||||
if (error.code !== 'ENOENT') throw error
|
if (error.code !== 'ENOENT') throw error
|
||||||
|
Loading…
Reference in New Issue
Block a user