Pitu il y a 6 ans
Parent
commit
71f2450431

+ 36 - 0
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;

+ 1 - 2
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
 				});

+ 18 - 4
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`,