From 4db167ec43806e20cc40932a292efc2909e69328 Mon Sep 17 00:00:00 2001 From: Pitu Date: Mon, 30 Sep 2019 07:24:37 +0000 Subject: Fix deletion of albums and links --- src/api/routes/albums/albumDELETE.js | 10 ++-------- src/api/routes/albums/albumPurgeDELETE.js | 29 +++++++++++++++++++++++++++++ src/api/routes/albums/link/linkDELETE.js | 4 ---- 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 src/api/routes/albums/albumPurgeDELETE.js (limited to 'src/api') diff --git a/src/api/routes/albums/albumDELETE.js b/src/api/routes/albums/albumDELETE.js index b43d046..2aa9942 100644 --- a/src/api/routes/albums/albumDELETE.js +++ b/src/api/routes/albums/albumDELETE.js @@ -3,11 +3,11 @@ const Util = require('../../utils/Util'); class albumDELETE extends Route { constructor() { - super('/album/:id/:purge*?', 'delete'); + super('/album/:id', 'delete'); } async run(req, res, db, user) { - const { id, purge } = req.params; + const { id } = req.params; if (!id) return res.status(400).json({ message: 'Invalid album ID supplied' }); /* @@ -17,12 +17,6 @@ class albumDELETE extends Route { if (!album) return res.status(400).json({ message: 'The file doesn\'t exist or doesn\'t belong to the user' }); try { - /* - Should we also delete every file of that album? - */ - if (purge) { - await Util.deleteAllFilesFromAlbum(id); - } /* Delete the album */ diff --git a/src/api/routes/albums/albumPurgeDELETE.js b/src/api/routes/albums/albumPurgeDELETE.js new file mode 100644 index 0000000..5a67c8e --- /dev/null +++ b/src/api/routes/albums/albumPurgeDELETE.js @@ -0,0 +1,29 @@ +const Route = require('../../structures/Route'); +const Util = require('../../utils/Util'); + +class albumDELETE extends Route { + constructor() { + super('/album/:id/purge', 'delete'); + } + + async run(req, res, db, user) { + const { id } = req.params; + if (!id) return res.status(400).json({ message: 'Invalid album ID supplied' }); + + /* + Check if the album exists + */ + const album = await db.table('albums').where({ id, userId: user.id }).first(); + if (!album) return res.status(400).json({ message: 'The file doesn\'t exist or doesn\'t belong to the user' }); + + try { + await Util.deleteAllFilesFromAlbum(id); + await db.table('albums').where({ id }).delete(); + return res.json({ message: 'The album was deleted successfully' }); + } catch (error) { + return super.error(res, error); + } + } +} + +module.exports = albumDELETE; diff --git a/src/api/routes/albums/link/linkDELETE.js b/src/api/routes/albums/link/linkDELETE.js index 3ec4d9d..7adcaac 100644 --- a/src/api/routes/albums/link/linkDELETE.js +++ b/src/api/routes/albums/link/linkDELETE.js @@ -7,10 +7,6 @@ class linkDELETE extends Route { } async run(req, res, db) { - console.log('------------------------------'); - console.log('YES HI'); - console.log('------------------------------'); - console.log('WHO NEEDS FANCY DEBUGGING TOOLS ANYWAYS'); const { identifier } = req.params; if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); -- cgit v1.2.3