diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/api/routes/albums/link/linkDELETE.js | 36 | ||||
| -rw-r--r-- | src/api/routes/albums/link/linkEditPOST.js | 3 | ||||
| -rw-r--r-- | src/site/pages/dashboard/albums.vue | 22 |
3 files changed, 55 insertions, 6 deletions
diff --git a/src/api/routes/albums/link/linkDELETE.js b/src/api/routes/albums/link/linkDELETE.js new file mode 100644 index 0000000..4f948ba --- /dev/null +++ b/src/api/routes/albums/link/linkDELETE.js @@ -0,0 +1,36 @@ +const Route = require('../../../structures/Route'); + +class linkDELETE extends Route { + constructor() { + super('/album/link/delete/:identifier', 'delete'); + } + + async run(req, res, db) { + const { identifier } = req.params; + if (!identifier) return res.status(400).json({ message: 'Invalid identifier supplied' }); + + try { + const link = await db.table('links') + .where({ identifier }) + .first(); + + if (!link) return res.status(400).json({ message: 'Identifier doesn\'t exist' }); + + await db.table('links') + .where({ id: link.id }) + .delete(); + await db.table('albumsLinks') + .where({ linkId: link.id }) + .delete(); + } catch (error) { + console.log(error); + return super.error(res, error); + } + + return res.json({ + message: 'Successfully deleted link' + }); + } +} + +module.exports = linkDELETE; diff --git a/src/api/routes/albums/link/linkEditPOST.js b/src/api/routes/albums/link/linkEditPOST.js index bb3c41b..1db0a53 100644 --- a/src/api/routes/albums/link/linkEditPOST.js +++ b/src/api/routes/albums/link/linkEditPOST.js @@ -8,7 +8,7 @@ class linkEditPOST extends Route { async run(req, res, db, user) { if (!req.body) return res.status(400).json({ message: 'No body provided' }); - const { identifier, enabled, enableDownload, expiresAt } = req.body; + const { identifier, enableDownload, expiresAt } = req.body; if (!identifier) return res.status(400).json({ message: 'Invalid album identifier supplied' }); /* @@ -21,7 +21,6 @@ class linkEditPOST extends Route { await db.table('links') .where({ identifier }) .update({ - enabled: enabled || false, enableDownload: enableDownload || false, expiresAt // This one should be null if not supplied }); diff --git a/src/site/pages/dashboard/albums.vue b/src/site/pages/dashboard/albums.vue index abf3334..a2e151e 100644 --- a/src/site/pages/dashboard/albums.vue +++ b/src/site/pages/dashboard/albums.vue @@ -228,10 +228,10 @@ </b-table-column> <b-table-column field="enabled" - label="Enabled" + label="Actions" centered> - <b-switch v-model="props.row.enabled" - @input="linkOptionsChanged(props.row)" /> + <button class="button is-danger" + @click="promptDeleteAlbumLink(props.row.identifier)">Delete link</button> </b-table-column> <!-- @@ -265,7 +265,6 @@ </div> </template> </b-table> - </div> </div> </div> @@ -301,6 +300,21 @@ export default { this.getAlbums(); }, methods: { + promptDeleteAlbumLink(identifier) { + this.$dialog.confirm({ + message: 'Are you sure you want to delete this album link?', + onConfirm: () => this.deleteAlbumLink(identifier) + }); + }, + async deleteAlbumLink(identifier) { + console.log('> deleteAlbumLink', identifier); + try { + const response = await this.axios.delete(`${this.config.baseURL}/album/link/delete/${identifier}`); + return this.$toast.open(response.data.message); + } catch (error) { + return this.$onPromiseError(error); + } + }, async linkOptionsChanged(link) { try { const response = await this.axios.post(`${this.config.baseURL}/album/link/edit`, |