Browse Source

Fixed some issues with limits and console.log's.

KrisVos130 8 years ago
parent
commit
8544c841ca

+ 1 - 0
backend/logic/actions/queueSongs.js

@@ -176,6 +176,7 @@ module.exports = {
 			(newSong, next) => {
 				const song = new db.models.queueSong(newSong);
 				song.save((err, song) => {
+					console.log(err);
 					if (err) return next(err);
 					next(null, song);
 				});

+ 7 - 7
backend/logic/actions/songs.js

@@ -176,12 +176,6 @@ module.exports = {
 	 */
 	add: hooks.adminRequired((session, song, cb, userId) => {
 		async.waterfall([
-			(next) => {
-				queueSongs.remove(session, song._id, () => {
-					next();
-				});
-			},
-
 			(next) => {
 				db.models.song.findOne({songId: song.songId}, next);
 			},
@@ -196,7 +190,13 @@ module.exports = {
 				newSong.acceptedBy = userId;
 				newSong.acceptedAt = Date.now();
 				newSong.save(next);
-			}
+			},
+
+			(next) => {
+				queueSongs.remove(session, song._id, () => {
+					next();
+				});
+			},
 		], (err) => {
 			if (err) {
 				err = utils.getError(err);

+ 12 - 5
backend/logic/db/index.js

@@ -129,8 +129,14 @@ let lib = {
 			lib.schemas.song.path('title').validate(songTitle, 'Invalid title.');
 			lib.schemas.queueSong.path('title').validate(songTitle, 'Invalid title.');
 
+			lib.schemas.song.path('artists').validate((artists) => {
+				return !(artists.length < 1 || artists.length > 10);
+			}, 'Invalid artists.');
+			lib.schemas.queueSong.path('artists').validate((artists) => {
+				return !(artists.length < 0 || artists.length > 10);
+			}, 'Invalid artists.');
+
 			let songArtists = (artists) => {
-				if (artists.length < 1 || artists.length > 10) return false;
 				return artists.filter((artist) => {
 						return (isLength(artist, 1, 32) && regex.ascii.test(artist) && artist !== "NONE");
 					}).length === artists.length;
@@ -146,11 +152,12 @@ let lib = {
 			lib.schemas.song.path('genres').validate(songGenres, 'Invalid genres.');
 			lib.schemas.queueSong.path('genres').validate(songGenres, 'Invalid genres.');
 
-			let songThumbnail = (thumbnail) => {
+			lib.schemas.song.path('thumbnail').validate((thumbnail) => {
 				return isLength(thumbnail, 8, 256);
-			};
-			lib.schemas.song.path('thumbnail').validate(songThumbnail, 'Invalid thumbnail.');
-			lib.schemas.queueSong.path('thumbnail').validate(songThumbnail, 'Invalid thumbnail.');
+			}, 'Invalid thumbnail.');
+			lib.schemas.queueSong.path('thumbnail').validate((thumbnail) => {
+				return isLength(thumbnail, 0, 256);
+			}, 'Invalid thumbnail.');
 
 			lib.schemas.playlist.path('displayName').validate((displayName) => {
 				return (isLength(displayName, 1, 16) && regex.ascii.test(displayName));

+ 0 - 1
backend/logic/io.js

@@ -39,7 +39,6 @@ module.exports = {
 				if (!socket.session) {
 					socket.session = {socketId: socket.id};
 				} else socket.session.socketId = socket.id;
-				console.log(socket.session);
 				next();
 			});
 		});

+ 0 - 2
backend/logic/tasks.js

@@ -52,9 +52,7 @@ let sessionClearingTask = (callback) => {
 			let keys = Object.keys(sessions);
 			async.each(keys, (sessionId, next2) => {
 				let session = sessions[sessionId];
-				console.log(Date.now() - session.refreshDate);
 				if (session && session.refreshDate && (Date.now() - session.refreshDate) < (60 * 60 * 24 * 30 * 1000)) return next2();
-				console.log(2);
 				if (!session) {
 					logger.info("TASK_SESSION_CLEAR", 'Removing an empty session.');
 					cache.hdel('sessions', sessionId, () => {

+ 2 - 0
frontend/components/Admin/QueueSongs.vue

@@ -86,12 +86,14 @@
 			add: function (song) {
 				this.socket.emit('songs.add', song, res => {
 					if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
+					else Toast.methods.addToast(res.message, 4000);
 				});
 			},
 			remove: function (id, index) {
 				console.log("Removing ", id);
 				this.socket.emit('queueSongs.remove', id, res => {
 					if (res.status == 'success') Toast.methods.addToast(res.message, 2000);
+				else Toast.methods.addToast(res.message, 4000);
 				});
 			},
 			init: function() {