Pārlūkot izejas kodu

Added button to delete orphaned station playlists

Kristian Vos 4 gadi atpakaļ
vecāks
revīzija
e6dd4cb18e

+ 35 - 0
backend/logic/actions/playlists.js

@@ -1499,5 +1499,40 @@ export default {
 				});
 			}
 		);
+	}),
+
+	/**
+	 * Deletes all orphaned station playlists
+	 *
+	 * @param {object} session - the session object automatically added by socket.io
+	 * @param {Function} cb - gets called with the result
+	 */
+	deleteOrphanedStationPlaylists: isAdminRequired(async function index(session, cb) {
+		async.waterfall(
+			[
+				next => {
+					PlaylistsModule.runJob("DELETE_ORPHANED_STATION_PLAYLISTS", {}, this)
+						.then(() => next())
+						.catch(next);
+				}
+			],
+			async err => {
+				if (err) {
+					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+					this.log(
+						"ERROR",
+						"PLAYLISTS_DELETE_ORPHANED_STATION_PLAYLISTS",
+						`Deleting orphaned station playlists failed. "${err}"`
+					);
+					return cb({ status: "failure", message: err });
+				}
+				this.log(
+					"SUCCESS",
+					"PLAYLISTS_DELETE_ORPHANED_STATION_PLAYLISTS",
+					"Deleting orphaned station playlists successfull."
+				);
+				return cb({ status: "success", message: "Success" });
+			}
+		);
 	})
 };

+ 28 - 0
frontend/src/pages/Admin/tabs/Playlists.vue

@@ -2,6 +2,14 @@
 	<div>
 		<metadata title="Admin | Playlists" />
 		<div class="container">
+			<button
+				class="button is-primary"
+				@click="deleteOrphanedStationPlaylists()"
+			>
+				Delete orphaned station playlists
+			</button>
+			<br />
+			<br />
 			<table class="table is-striped">
 				<thead>
 					<tr>
@@ -59,6 +67,8 @@
 <script>
 import { mapState, mapActions } from "vuex";
 
+import Toast from "toasters";
+
 // import EditPlaylist from "../../../components/modals/EditPlaylist/index.vue";
 import UserIdToUsername from "../../../components/common/UserIdToUsername.vue";
 
@@ -122,6 +132,24 @@ export default {
 			});
 			return this.utils.formatTimeLong(length);
 		},
+		deleteOrphanedStationPlaylists() {
+			this.socket.emit(
+				"playlists.deleteOrphanedStationPlaylists",
+				res => {
+					if (res.status === "success") {
+						new Toast({
+							content: `${res.message}`,
+							timeout: 4000
+						});
+					} else {
+						new Toast({
+							content: `Error: ${res.message}`,
+							timeout: 8000
+						});
+					}
+				}
+			);
+		},
 		...mapActions("modalVisibility", ["openModal"])
 	}
 };