diff options
Diffstat (limited to 'src/api/routes/files')
| -rw-r--r-- | src/api/routes/files/tagAddPOST.js | 27 | ||||
| -rw-r--r-- | src/api/routes/files/tagDelPOST.js | 27 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/api/routes/files/tagAddPOST.js b/src/api/routes/files/tagAddPOST.js new file mode 100644 index 0000000..9d334d8 --- /dev/null +++ b/src/api/routes/files/tagAddPOST.js @@ -0,0 +1,27 @@ +const Route = require('../../structures/Route'); + +class tagAddPOST extends Route { + constructor() { + super('/file/tag/add', 'post'); + } + + run(req, res, db) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { fileId, tagNames } = req.body; + if (!fileId || !tagNames.length) return res.status(400).json({ message: 'No tags provided' }); + + tagNames.forEach(async tag => { + try { + await db.table('fileTags').insert({ fileId, tag }); + } catch (error) { + return super.error(res, error); + } + }); + + return res.json({ + message: 'Successfully added file to album' + }); + } +} + +module.exports = tagAddPOST; diff --git a/src/api/routes/files/tagDelPOST.js b/src/api/routes/files/tagDelPOST.js new file mode 100644 index 0000000..fd6bbd0 --- /dev/null +++ b/src/api/routes/files/tagDelPOST.js @@ -0,0 +1,27 @@ +const Route = require('../../structures/Route'); + +class albumDelPOST extends Route { + constructor() { + super('/file/album/del', 'post'); + } + + async run(req, res, db) { + if (!req.body) return res.status(400).json({ message: 'No body provided' }); + const { fileId, albumId } = req.body; + if (!fileId || !albumId) return res.status(400).json({ message: 'No id provided' }); + + try { + await db.table('albumsFiles') + .where({ fileId, albumId }) + .delete(); + } catch (error) { + return super.error(res, error); + } + + return res.json({ + message: 'Successfully removed file from album' + }); + } +} + +module.exports = albumDelPOST; |