KrisVos130 8 лет назад
Родитель
Сommit
366548bd55

+ 18 - 2
backend/logic/actions/queueSongs.js

@@ -54,16 +54,32 @@ module.exports = {
 		return cb({ status: 'success', message: 'Song was removed successfully' });
 	}),
 
-	add: hooks.loginRequired((session, id, cb, userId) => {
+	add: hooks.loginRequired((session, songId, cb, userId) => {
 		//TODO Check if id is valid
 		//TODO Check if id is already in queue/rotation
 
 		let requestedAt = Date.now();
 
 		async.waterfall([
+			(next) => {
+				db.models.queueSong.findOne({_id: songId}, (err, song) => {
+					if (err) return next('Something went wrong while getting the song from the Database.');
+					if (song) return next('This song is already in the queue.');
+					next();
+				});
+			},
+
+			(next) => {
+				db.models.song.findOne({_id: songId}, (err, song) => {
+					if (err) return next('Something went wrong while getting the song from the Database.');
+					if (song) return next('This song has already been added.');
+					next();
+				});
+			},
+
 			// Get YouTube data from id
 			(next) => {
-				utils.getSongFromYouTube(id, (song) => {
+				utils.getSongFromYouTube(songId, (song) => {
 					song.artists = [];
 					song.genres = [];
 					song.skipDuration = 0;

+ 1 - 3
backend/logic/actions/stations.js

@@ -404,6 +404,7 @@ module.exports = {
 					}
 				});
 				if (has) return cb({'status': 'failure', 'message': 'That song has already been added to the queue.'});
+				if (station.currentSong && station.currentSong._id === songId) return cb({'status': 'failure', 'message': 'That song is currently playing.'});
 
 				songs.getSong(songId, (err, song) => {
 					if (err) {
@@ -423,9 +424,6 @@ module.exports = {
 							if (err) return cb({'status': 'failure', 'message': 'Something went wrong.'});
 							stations.updateStation(stationId, (err, station) => {
 								if (err) return cb(err);
-								if (station.currentSong === null || station.currentSong._id === undefined) {
-									notifications.schedule(`stations.nextSong?id=${stationId}`, 1);
-								}
 								cache.pub('station.queueUpdate', stationId);
 								cb({'status': 'success', 'message': 'Added that song to the queue.'});
 							});

+ 2 - 2
backend/logic/stations.js

@@ -63,12 +63,12 @@ module.exports = {
 							if (isNaN(timeLeft)) timeLeft = -1;
 							if (station.currentSong.duration * 1000 < timeLeft || timeLeft < 0) {
 								console.log("Test");
-								notifications.schedule(`stations.nextSong?id=${station._id}`, 1);
+								_this.skipStation(station._id)();
 							} else {
 								notifications.schedule(`stations.nextSong?id=${station._id}`, timeLeft);
 							}
 						} else {
-							notifications.schedule(`stations.nextSong?id=${station._id}`, 1);
+							_this.skipStation(station._id)();
 						}
 					} else {
 						notifications.unschedule(`stations.nextSong?id${station._id}`);

+ 17 - 7
frontend/components/Modals/AddSongToQueue.vue

@@ -50,13 +50,23 @@
 		methods: {
 			addSongToQueue: function (songId) {
 				let _this = this;
-				_this.socket.emit('stations.addToQueue', _this.$parent.stationId, songId, data => {
-					if (data.status !== 'success') {
-						Toast.methods.addToast(`Error: ${data.message}`, 8000);
-					} else {
-						Toast.methods.addToast(`${data.message}`, 4000);
-					}
-				});
+				if (_this.$parent.type === 'community') {
+					_this.socket.emit('stations.addToQueue', _this.$parent.stationId, songId, data => {
+						if (data.status !== 'success') {
+							Toast.methods.addToast(`Error: ${data.message}`, 8000);
+						} else {
+							Toast.methods.addToast(`${data.message}`, 4000);
+						}
+					});
+				} else {
+					_this.socket.emit('queueSongs.add', songId, data => {
+						if (data.status !== 'success') {
+							Toast.methods.addToast(`Error: ${data.message}`, 8000);
+						} else {
+							Toast.methods.addToast(`${data.message}`, 4000);
+						}
+					});
+				}
 			},
 			submitQuery: function () {
 				let _this = this;

+ 1 - 1
frontend/components/Sidebars/Queue.vue

@@ -6,7 +6,7 @@
 			<article class="media">
 				<figure class="media-left">
 					<p class="image is-64x64">
-						<img :src="$parent.currentSong.thumbnail">
+						<img :src="$parent.currentSong.thumbnail" onerror="this.src='/assets/notes.png'">
 					</p>
 				</figure>
 				<div class="media-content">

+ 0 - 5
frontend/components/Station/CommunityHeader.vue

@@ -4,11 +4,6 @@
 			<a class="nav-item logo" href="#" v-link="{ path: '/' }" @click="this.$dispatch('leaveStation', title)">
 				Musare
 			</a>
-			<a class="nav-item" href="#" @click="$parent.toggleModal('addSongToQueue')">
-				<span class="icon">
-					<i class="material-icons">playlist_add</i>
-				</span>
-			</a>
 			<a v-if="$parent.$parent.role === 'admin'" class="nav-item" href="#" @click="$parent.skipStation()">
 				<span class="icon">
 					<i class="material-icons">skip_next</i>

+ 5 - 0
frontend/components/Station/OfficialHeader.vue

@@ -4,6 +4,11 @@
 			<a class="nav-item logo" href="#" v-link="{ path: '/' }" @click="this.$dispatch('leaveStation', title)">
 				Musare
 			</a>
+			<a class="nav-item" href="#" @click="$parent.toggleModal('addSongToQueue')">
+				<span class="icon">
+					<i class="material-icons">playlist_add</i>
+				</span>
+			</a>
 			<a class="nav-item" href="#">
 				<span class="icon">
 					<i class="material-icons">flag</i>

+ 1 - 1
frontend/components/Station/Station.vue

@@ -139,7 +139,7 @@
 									local.player.seekTo(local.timeBeforePause / 1000, true);
 									local.player.pauseVideo();
 								}
-								if (event.data === 2 && !local.paused) {
+								if (event.data === 2 && !local.paused && !local.noSong) {
 									local.player.seekTo(local.getTimeElapsed() / 1000, true);
 									local.player.playVideo();
 								}