Browse Source

Minor changes to Kris's commits

theflametrooper 8 years ago
parent
commit
020ce615c4
3 changed files with 23 additions and 40 deletions
  1. 14 18
      backend/logic/actions/playlists.js
  2. 1 3
      backend/logic/actions/stations.js
  3. 8 19
      backend/logic/utils.js

+ 14 - 18
backend/logic/actions/playlists.js

@@ -73,7 +73,7 @@ let lib = {
 
 	indexForUser: hooks.loginRequired((session, cb, userId) => {
 		db.models.playlist.find({ createdBy: userId }, (err, playlists) => {
-			if (err) return cb({ status: 'failure', message: 'Something went wrong when getting the playlists.'});;
+			if (err) return cb({ status: 'failure', message: 'Something went wrong when getting the playlists'});;
 			cb({
 				status: 'success',
 				data: playlists
@@ -107,7 +107,7 @@ let lib = {
 
 	getPlaylist: hooks.loginRequired((session, id, cb, userId) => {
 		playlists.getPlaylist(id, (err, playlist) => {
-			if (err || playlist.createdBy !== userId) return cb({status: 'success', message: 'Playlist not found.'});
+			if (err || playlist.createdBy !== userId) return cb({status: 'success', message: 'Playlist not found'});
 			if (err == null) return cb({
 				status: 'success',
 				data: playlist
@@ -131,7 +131,7 @@ let lib = {
 		async.waterfall([
 			(next) => {
 				playlists.getPlaylist(playlistId, (err, playlist) => {
-					if (err || !playlist || playlist.createdBy !== userId) return next('Something went wrong when trying to get the playlist.');
+					if (err || !playlist || playlist.createdBy !== userId) return next('Something went wrong when trying to get the playlist');
 
 					let found = false;
 					playlist.songs.forEach((song) => {
@@ -159,7 +159,7 @@ let lib = {
 				});
 			},
 			(newSong, next) => {
-				db.models.playlist.update({_id: playlistId}, {$push: {songs: newSong}}, (err) => {
+				db.models.playlist.update({ _id: playlistId }, { $push: { songs: newSong } }, (err) => {
 					if (err) {
 						console.error(err);
 						return next('Failed to add song to playlist');
@@ -190,9 +190,7 @@ let lib = {
 			(songs, next) => {
 				let processed = 0;
 				function checkDone() {
-					if (processed === songs.length) {
-						next();
-					}
+					if (processed === songs.length) next();
 				}
 				for (let s = 0; s < songs.length; s++) {
 					lib.addSongToPlaylist(session, songs[s].contentDetails.videoId, playlistId, () => {
@@ -203,7 +201,7 @@ let lib = {
 			},
 			(next) => {
 				playlists.getPlaylist(playlistId, (err, playlist) => {
-					if (err || !playlist || playlist.createdBy !== userId) return next('Something went wrong while trying to get the playlist.');
+					if (err || !playlist || playlist.createdBy !== userId) return next('Something went wrong while trying to get the playlist');
 
 					next(null, playlist);
 				});
@@ -218,7 +216,7 @@ let lib = {
 
 	removeSongFromPlaylist: hooks.loginRequired((session, songId, playlistId, cb, userId) => {
 		playlists.getPlaylist(playlistId, (err, playlist) => {
-			if (err || !playlist || playlist.createdBy !== userId) return cb({ status: 'failure', message: 'Something went wrong when getting the playlist.'});
+			if (err || !playlist || playlist.createdBy !== userId) return cb({ status: 'failure', message: 'Something went wrong when getting the playlist'});
 
 			for (let z = 0; z < playlist.songs.length; z++) {
 				if (playlist.songs[z]._id == songId) playlist.songs.shift(playlist.songs[z]);
@@ -250,7 +248,7 @@ let lib = {
 
 	moveSongToTop: hooks.loginRequired((session, playlistId, songId, cb, userId) => {
 		playlists.getPlaylist(playlistId, (err, playlist) => {
-			if (err || !playlist || playlist.createdBy !== userId) return cb({ status: 'failure', message: 'Something went wrong when getting the playlist.'});
+			if (err || !playlist || playlist.createdBy !== userId) return cb({ status: 'failure', message: 'Something went wrong when getting the playlist'});
 			let found = false;
 			let foundSong;
 			playlist.songs.forEach((song) => {
@@ -263,7 +261,7 @@ let lib = {
 			if (found) {
 				db.models.playlist.update({_id: playlistId}, {$pull: {songs: {_id: songId}}}, (err) => {
 					console.log(err);
-					if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song.'});
+					if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song'});
 					db.models.playlist.update({_id: playlistId}, {
 						$push: {
 							songs: {
@@ -273,7 +271,7 @@ let lib = {
 						}
 					}, (err) => {
 						console.log(err);
-						if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song.'});
+						if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song'});
 						playlists.updatePlaylist(playlistId, (err) => {
 							if (err) return cb({ status: 'failure', message: err});
 							cache.pub('playlist.moveSongToTop', {playlistId, songId, userId: userId});
@@ -289,7 +287,7 @@ let lib = {
 
 	moveSongToBottom: hooks.loginRequired((session, playlistId, songId, cb, userId) => {
 		playlists.getPlaylist(playlistId, (err, playlist) => {
-			if (err || !playlist || playlist.createdBy !== userId) return cb({ status: 'failure', message: 'Something went wrong when getting the playlist.'});
+			if (err || !playlist || playlist.createdBy !== userId) return cb({ status: 'failure', message: 'Something went wrong when getting the playlist'});
 			let found = false;
 			let foundSong;
 			playlist.songs.forEach((song) => {
@@ -302,12 +300,12 @@ let lib = {
 			if (found) {
 				db.models.playlist.update({_id: playlistId}, {$pull: {songs: {_id: songId}}}, (err) => {
 					console.log(err);
-					if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song.'});
+					if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song'});
 					db.models.playlist.update({_id: playlistId}, {
 						$push: { songs: foundSong }
 					}, (err) => {
 						console.log(err);
-						if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song.'});
+						if (err) return cb({status: 'failure', message: 'Something went wrong when moving the song'});
 						playlists.updatePlaylist(playlistId, (err) => {
 							if (err) return cb({ status: 'failure', message: err});
 							cache.pub('playlist.moveSongToBottom', {playlistId, songId, userId: userId});
@@ -315,9 +313,7 @@ let lib = {
 						})
 					});
 				});
-			} else {
-				return cb({status: 'failure', message: 'Song not found.'});
-			}
+			} else return cb({status: 'failure', message: 'Song not found'});
 		});
 	}),
 

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

@@ -249,9 +249,7 @@ module.exports = {
 				if (err) return cb({ status: 'failure', message: 'Something went wrong when saving the station.' });
 				stations.updateStation(stationId, (err, station) => {
 					cache.pub('station.voteSkipSong', stationId);
-					if (station.currentSong && station.currentSong.skipVotes.length >= 3) {
-						stations.skipStation(stationId)();
-					}
+					if (station.currentSong && station.currentSong.skipVotes.length >= 3) stations.skipStation(stationId)();
 					cb({ status: 'success', message: 'Successfully voted to skip the song.' });
 				})
 			});

+ 8 - 19
backend/logic/utils.js

@@ -183,9 +183,7 @@ module.exports = {
 		let socket = this.socketFromSession(socketId);
 		let rooms = socket.rooms;
 		for (let room in rooms) {
-			if (room.indexOf('song.') !== -1) {
-				socket.leave(rooms);
-			}
+			if (room.indexOf('song.') !== -1) socket.leave(rooms);
 		}
 		socket.join(room);
 	},
@@ -194,9 +192,7 @@ module.exports = {
 			let socket = sockets[id];
 			let rooms = socket.rooms;
 			for (let room in rooms) {
-				if (room.indexOf('song.') !== -1) {
-					socket.leave(room);
-				}
+				if (room.indexOf('song.') !== -1) socket.leave(room);
 			}
 			socket.join(room);
 		}
@@ -206,9 +202,7 @@ module.exports = {
 			let socket = sockets[id];
 			let rooms = socket.rooms;
 			for (let room in rooms) {
-				if (room.indexOf('song.') !== -1) {
-					socket.leave(room);
-				}
+				if (room.indexOf('song.') !== -1) socket.leave(room);
 			}
 		}
 	},
@@ -230,9 +224,7 @@ module.exports = {
 		let roomSockets = [];
 		for (let id in sockets) {
 			let socket = sockets[id];
-			if (socket.rooms[room]) {
-				roomSockets.push(socket);
-			}
+			if (socket.rooms[room]) roomSockets.push(socket);
 		}
 		return roomSockets;
 	},
@@ -251,9 +243,7 @@ module.exports = {
 				youtubeRequestCallbacks.splice(0, 1);
 				if (youtubeRequestCallbacks.length > 0) {
 					youtubeRequestCallbacks[0].cb(youtubeRequestCallbacks[0].songId);
-				} else {
-					youtubeRequestsActive = false;
-				}
+				} else youtubeRequestsActive = false;
 
 				if (err) {
 					console.error(err);
@@ -316,12 +306,11 @@ module.exports = {
 					console.error(err);
 					return next('Failed to find playlist from YouTube');
 				}
-				body = JSON.parse(body);
 
+				body = JSON.parse(body);
 				songs = songs.concat(body.items);
-				if (body.nextPageToken) {
-					getPage(body.nextPageToken, songs);
-				} else {
+				if (body.nextPageToken) getPage(body.nextPageToken, songs);
+				else {
 					console.log(songs);
 					cb(songs);
 				}