Browse Source

Revert "refactor: Import album tweaks"

This reverts commit 994e862784c6738e5c8e59c4e57d8c65cd7cf9a0.
Kristian Vos 2 years ago
parent
commit
f4cffd192a

+ 3 - 0
backend/logic/actions/users.js

@@ -220,8 +220,11 @@ CacheModule.runJob("SUB", {
 CacheModule.runJob("SUB", {
 	channel: "longJob.added",
 	cb: ({ jobId, userId }) => {
+		console.log(1111, jobId, userId);
 		WSModule.runJob("SOCKETS_FROM_USER", { userId }).then(sockets => {
+			console.log(2222, sockets.length);
 			sockets.forEach(socket => {
+				console.log(3333);
 				socket.dispatch("keep.event:longJob.added", {
 					data: {
 						jobId

+ 75 - 0
frontend/src/components/modals/ImportAlbum.vue

@@ -224,6 +224,22 @@
 					</div>
 				</div>
 				<div class="import-youtube-playlist">
+					<p class="control is-expanded">
+						<input
+							class="input"
+							type="text"
+							placeholder="Enter YouTube Playlist URL here..."
+							v-model="search.playlist.query"
+							@keyup.enter="importPlaylist()"
+						/>
+					</p>
+					<button
+						class="button is-fullwidth is-info"
+						@click="importPlaylist()"
+					>
+						<i class="material-icons icon-with-button">publish</i
+						>Import
+					</button>
 					<button
 						class="button is-fullwidth is-danger"
 						@click="resetTrackSongs()"
@@ -327,6 +343,12 @@ export default {
 			isImportingPlaylist: false,
 			trackSongs: [],
 			songsToEdit: [],
+			// currentEditSongIndex: 0,
+			search: {
+				playlist: {
+					query: ""
+				}
+			},
 			discogsQuery: "",
 			discogs: {
 				apiResults: [],
@@ -437,6 +459,59 @@ export default {
 		log(evt) {
 			window.console.log(evt);
 		},
+		importPlaylist() {
+			if (this.isImportingPlaylist)
+				return new Toast("A playlist is already importing.");
+			this.isImportingPlaylist = true;
+
+			// import query is blank
+			if (!this.search.playlist.query)
+				return new Toast("Please enter a YouTube playlist URL.");
+
+			const regex = /[\\?&]list=([^&#]*)/;
+			const splitQuery = regex.exec(this.search.playlist.query);
+
+			if (!splitQuery) {
+				return new Toast({
+					content: "Please enter a valid YouTube playlist URL.",
+					timeout: 4000
+				});
+			}
+
+			// don't give starting import message instantly in case of instant error
+			setTimeout(() => {
+				if (this.isImportingPlaylist) {
+					new Toast(
+						"Starting to import your playlist. This can take some time to do."
+					);
+				}
+			}, 750);
+
+			return this.socket.dispatch(
+				"songs.requestSet",
+				this.search.playlist.query,
+				false,
+				true,
+				res => {
+					this.isImportingPlaylist = false;
+					const songs = res.songs.filter(song => !song.verified);
+					const songsAlreadyVerified =
+						res.songs.length - songs.length;
+					this.setPlaylistSongs(songs);
+					if (this.discogsAlbum.tracks) {
+						this.trackSongs = this.discogsAlbum.tracks.map(
+							() => []
+						);
+						this.tryToAutoMove();
+					}
+					if (songsAlreadyVerified > 0)
+						new Toast(
+							`${songsAlreadyVerified} songs were already verified, skipping those.`
+						);
+					return new Toast({ content: res.message, timeout: 20000 });
+				}
+			);
+		},
 		tryToAutoMove() {
 			const { tracks } = this.discogsAlbum;
 			const { trackSongs } = this;

+ 11 - 1
frontend/src/pages/Admin/Songs/Import.vue

@@ -473,6 +473,16 @@ export default {
 			socket: "websockets/getSocket"
 		})
 	},
+	mounted() {
+		// this.socket.dispatch("youtube.getRequestSetAdminLongJobs", {
+		// 	cb: res => {
+		// 		console.log(111, res);
+		// 	},
+		// 	onProgress: res => {
+		// 		console.log(222, res);
+		// 	}
+		// });
+	},
 	methods: {
 		openAdvancedTable(importJob) {
 			const filter = {
@@ -481,7 +491,7 @@ export default {
 						data: importJob._id,
 						filter: {
 							name: "importJob",
-							displayName: "Import Job",
+							displayName: "Import%20job",
 							property: "importJob",
 							filterTypes: ["special"],
 							defaultFilterType: "special"

+ 1 - 1
frontend/src/pages/Admin/YouTube/Videos.vue

@@ -286,7 +286,7 @@ export default {
 				},
 				{
 					name: "importJob",
-					displayName: "Import Job",
+					displayName: "Import job",
 					property: "importJob",
 					filterTypes: ["special"],
 					defaultFilterType: "special"

+ 9 - 3
frontend/src/store/modules/longJobs.js

@@ -1,7 +1,14 @@
 /* eslint no-param-reassign: 0 */
 
 const state = {
-	activeJobs: [],
+	activeJobs: [
+		// {
+		// 	id: 1,
+		// 	name: "test",
+		// 	status: "success",
+		// 	message: "test"
+		// }
+	],
 	removedJobIds: []
 };
 
@@ -20,8 +27,7 @@ const mutations = {
 				state.activeJobs.push({
 					id,
 					name,
-					status,
-					message
+					status
 				});
 			else
 				state.activeJobs.forEach((activeJob, index) => {

+ 8 - 1
frontend/src/store/modules/modals/importAlbum.js

@@ -19,6 +19,8 @@ export default {
 		toggleDiscogsAlbum: ({ commit }) => {
 			commit("toggleDiscogsAlbum");
 		},
+		setPlaylistSongs: ({ commit }, playlistSongs) =>
+			commit("setPlaylistSongs", playlistSongs),
 		updatePlaylistSongs: ({ commit }, playlistSongs) =>
 			commit("updatePlaylistSongs", playlistSongs),
 		updateEditingSongs: ({ commit }, editingSongs) =>
@@ -31,7 +33,6 @@ export default {
 	},
 	mutations: {
 		init(state, { songs }) {
-			state.originalPlaylistSongs = JSON.parse(JSON.stringify(songs));
 			state.playlistSongs = JSON.parse(JSON.stringify(songs));
 		},
 		showDiscogsTab(state, tab) {
@@ -49,6 +50,12 @@ export default {
 		toggleDiscogsAlbum(state) {
 			state.discogsAlbum.expanded = !state.discogsAlbum.expanded;
 		},
+		setPlaylistSongs(state, playlistSongs) {
+			state.originalPlaylistSongs = JSON.parse(
+				JSON.stringify(playlistSongs)
+			);
+			state.playlistSongs = JSON.parse(JSON.stringify(playlistSongs));
+		},
 		updatePlaylistSongs(state, playlistSongs) {
 			state.playlistSongs = JSON.parse(JSON.stringify(playlistSongs));
 		},