feat: new api /api/upload/get/:identifier

this api only returns file that the user owns (thus token must be set)
This commit is contained in:
Bobby 2022-06-28 11:57:56 +07:00
parent 7463a72840
commit 5d1bea39ef
No known key found for this signature in database
GPG Key ID: 941839794CBF5A09
2 changed files with 32 additions and 1 deletions

View File

@ -1594,4 +1594,35 @@ self.list = async (req, res, next) => {
}
}
/** Get file info */
self.get = async (req, res, next) => {
try {
const user = await utils.authorize(req)
const ismoderator = perms.is(user, 'moderator')
const identifier = req.params.identifier
if (identifier === undefined) {
throw new ClientError('No identifier provided.')
}
const file = await utils.db.table('files')
.where('name', identifier)
.where(function () {
if (!ismoderator) {
this.where('userid', user.id)
}
})
.first()
if (!file) {
throw new ClientError('File not found.', { statusCode: 404 })
}
await res.json({ success: true, file })
} catch (error) {
return apiErrorsHandler(error, req, res, next)
}
}
module.exports = self

View File

@ -32,9 +32,9 @@ routes.get('/uploads', (req, res, next) => uploadController.list(req, res, next)
routes.get('/uploads/:page', (req, res, next) => uploadController.list(req, res, next))
routes.post('/upload', (req, res, next) => uploadController.upload(req, res, next))
routes.post('/upload/delete', (req, res, next) => uploadController.delete(req, res, next))
// routes.get('/upload/delete/:name', (req, res, next) => uploadController.delete(req, res, next))
routes.post('/upload/bulkdelete', (req, res, next) => uploadController.bulkDelete(req, res, next))
routes.post('/upload/finishchunks', (req, res, next) => uploadController.finishChunks(req, res, next))
routes.get('/upload/get/:identifier', (req, res, next) => uploadController.get(req, res, next))
routes.post('/upload/:albumid', (req, res, next) => uploadController.upload(req, res, next))
routes.get('/album/get/:identifier', (req, res, next) => albumsController.get(req, res, next))
routes.get('/album/zip/:identifier', (req, res, next) => albumsController.generateZip(req, res, next))