mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-02-07 13:59:01 +00:00
Updated uploadController.js
Filters input in Manage Uploads will now display error if it's filled with invalid filter/sort keys. SQLITE_ERROR will also now be forwarded to users if they're moderators. The expectation is to only display it when used through Manage Uploads.
This commit is contained in:
parent
e5041a6d0b
commit
940be1ad99
@ -835,6 +835,9 @@ self.list = async (req, res) => {
|
|||||||
.select('id', 'username')
|
.select('id', 'username')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filters && !(_filters.uploaders.length || _filters.names.length || _filters.ips.length || _filters.flags.nouser || _filters.flags.noip || _orderBy.length))
|
||||||
|
return res.json({ success: false, description: 'No valid filter or sort keys were used. Please confirm the valid keys through the Help? button!' })
|
||||||
|
|
||||||
function filter () {
|
function filter () {
|
||||||
if (req.params.id !== undefined)
|
if (req.params.id !== undefined)
|
||||||
this.where('albumid', req.params.id)
|
this.where('albumid', req.params.id)
|
||||||
@ -861,6 +864,7 @@ self.list = async (req, res) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// Query uploads count for pagination
|
// Query uploads count for pagination
|
||||||
const count = await db.table('files')
|
const count = await db.table('files')
|
||||||
.where(filter)
|
.where(filter)
|
||||||
@ -946,6 +950,25 @@ self.list = async (req, res) => {
|
|||||||
users[user.id] = user.username
|
users[user.id] = user.username
|
||||||
|
|
||||||
return res.json({ success: true, files, count, users, basedomain })
|
return res.json({ success: true, files, count, users, basedomain })
|
||||||
|
} catch (error) {
|
||||||
|
// If moderator, capture SQLITE_ERROR and use its error message for the response's description
|
||||||
|
let errorString
|
||||||
|
if (ismoderator && error.code === 'SQLITE_ERROR') {
|
||||||
|
const match = error.message.match(/SQLITE_ERROR: .*$/)
|
||||||
|
errorString = match && match[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// If not proper SQLITE_ERROR, log to console
|
||||||
|
if (!errorString) {
|
||||||
|
logger.error(error)
|
||||||
|
res.status(500) // Use 500 status code
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.json({
|
||||||
|
success: false,
|
||||||
|
description: errorString || 'An unexpected error occurred. Try again?'
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = self
|
module.exports = self
|
||||||
|
Loading…
Reference in New Issue
Block a user