diff options
| author | Pitu <[email protected]> | 2019-09-30 07:06:35 +0000 |
|---|---|---|
| committer | Pitu <[email protected]> | 2019-09-30 07:06:35 +0000 |
| commit | 0d36f0d69aaf10fad4608f630a8f7dfe263ea74c (patch) | |
| tree | 8200f7553b492ad1d38f513ca46a07b2c6c9adfa /src/api | |
| parent | feature: album links (diff) | |
| download | host.fuwn.me-0d36f0d69aaf10fad4608f630a8f7dfe263ea74c.tar.xz host.fuwn.me-0d36f0d69aaf10fad4608f630a8f7dfe263ea74c.zip | |
feature: tags logic
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/routes/files/tagAddPOST.js | 27 | ||||
| -rw-r--r-- | src/api/routes/files/tagDelPOST.js | 27 | ||||
| -rw-r--r-- | src/api/routes/tags/tagPOST.js | 2 |
3 files changed, 55 insertions, 1 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; diff --git a/src/api/routes/tags/tagPOST.js b/src/api/routes/tags/tagPOST.js index 0df36e1..489dac3 100644 --- a/src/api/routes/tags/tagPOST.js +++ b/src/api/routes/tags/tagPOST.js @@ -27,7 +27,7 @@ class tagPOST extends Route { editedAt: now }); - return res.json({ message: 'The album was created successfully' }); + return res.json({ message: 'The tag was created successfully' }); } } |