mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-18 17:21:33 +00:00
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:
parent
7463a72840
commit
5d1bea39ef
@ -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
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user