Browse Source

Merge branch 'odiffey-owen-reduce-limits' into polishing

Kristian Vos 2 years ago
parent
commit
bfa5c2e377
2 changed files with 56 additions and 50 deletions
  1. 47 41
      backend/logic/actions/stations.js
  2. 9 9
      backend/logic/db/index.js

+ 47 - 41
backend/logic/actions/stations.js

@@ -3049,50 +3049,56 @@ export default {
 				(song, station, next) => {
 					song.requestedBy = session.userId;
 					song.requestedAt = Date.now();
-					let totalDuration = 0;
-					station.queue.forEach(song => {
-						totalDuration += song.duration;
-					});
-					if (totalDuration >= 3600 * 3) return next("The max length of the queue is 3 hours.");
-					return next(null, song, station);
-				},
-
-				(song, station, next) => {
-					if (station.queue.length === 0) return next(null, song, station);
-					let totalDuration = 0;
-					const userId = station.queue[station.queue.length - 1].requestedBy;
-					station.queue.forEach(song => {
-						if (userId === song.requestedBy) {
-							totalDuration += song.duration;
-						}
-					});
-
-					if (totalDuration >= 900) return next("The max length of songs per user is 15 minutes.");
-					return next(null, song, station);
-				},
-
-				(song, station, next) => {
-					if (station.queue.length === 0) return next(null, song);
-					let totalSongs = 0;
-					const userId = station.queue[station.queue.length - 1].requestedBy;
-					station.queue.forEach(song => {
-						if (userId === song.requestedBy) {
-							totalSongs += 1;
-						}
-					});
-
-					if (totalSongs <= 2) return next(null, song);
-					if (totalSongs > 3)
-						return next("The max amount of songs per user is 3, and only 2 in a row is allowed.");
-					if (
-						station.queue[station.queue.length - 2].requestedBy !== userId ||
-						station.queue[station.queue.length - 3] !== userId
-					)
-						return next("The max amount of songs per user is 3, and only 2 in a row is allowed.");
-
 					return next(null, song);
 				},
 
+				// (song, station, next) => {
+				// 	song.requestedBy = session.userId;
+				// 	song.requestedAt = Date.now();
+				// 	let totalDuration = 0;
+				// 	station.queue.forEach(song => {
+				// 		totalDuration += song.duration;
+				// 	});
+				// 	if (totalDuration >= 3600 * 3) return next("The max length of the queue is 3 hours.");
+				// 	return next(null, song, station);
+				// },
+
+				// (song, station, next) => {
+				// 	if (station.queue.length === 0) return next(null, song, station);
+				// 	let totalDuration = 0;
+				// 	const userId = station.queue[station.queue.length - 1].requestedBy;
+				// 	station.queue.forEach(song => {
+				// 		if (userId === song.requestedBy) {
+				// 			totalDuration += song.duration;
+				// 		}
+				// 	});
+
+				// 	if (totalDuration >= 900) return next("The max length of songs per user is 15 minutes.");
+				// 	return next(null, song, station);
+				// },
+
+				// (song, station, next) => {
+				// 	if (station.queue.length === 0) return next(null, song);
+				// 	let totalSongs = 0;
+				// 	const userId = station.queue[station.queue.length - 1].requestedBy;
+				// 	station.queue.forEach(song => {
+				// 		if (userId === song.requestedBy) {
+				// 			totalSongs += 1;
+				// 		}
+				// 	});
+
+				// 	if (totalSongs <= 2) return next(null, song);
+				// 	if (totalSongs > 3)
+				// 		return next("The max amount of songs per user is 3, and only 2 in a row is allowed.");
+				// 	if (
+				// 		station.queue[station.queue.length - 2].requestedBy !== userId ||
+				// 		station.queue[station.queue.length - 3] !== userId
+				// 	)
+				// 		return next("The max amount of songs per user is 3, and only 2 in a row is allowed.");
+
+				// 	return next(null, song);
+				// },
+
 				(song, next) => {
 					stationModel.updateOne(
 						{ _id: stationId },

+ 9 - 9
backend/logic/db/index.js

@@ -165,11 +165,11 @@ class _DBModule extends CoreClass {
 							new Promise((resolve, reject) => {
 								this.models.station.countDocuments({ owner }, (err, c) => {
 									if (err) reject(new Error("A mongo error happened."));
-									else if (c >= 3) reject(new Error("User already has 3 stations."));
+									else if (c >= 25) reject(new Error("User already has 25 stations."));
 									else resolve();
 								});
 							}),
-						message: "User already has 3 stations."
+						message: "User already has 25 stations."
 					});
 
 					/*
@@ -245,17 +245,17 @@ class _DBModule extends CoreClass {
 						);
 
 					this.schemas.playlist.path("createdBy").validate(createdBy => {
-						this.models.playlist.countDocuments({ createdBy }, (err, c) => !(err || c >= 10));
-					}, "Max 10 playlists per user.");
+						this.models.playlist.countDocuments({ createdBy }, (err, c) => !(err || c >= 100));
+					}, "Max 100 playlists per user.");
 
 					this.schemas.playlist
 						.path("songs")
-						.validate(songs => songs.length <= 5000, "Max 5000 songs per playlist.");
+						.validate(songs => songs.length <= 10000, "Max 10000 songs per playlist.");
 
-					this.schemas.playlist.path("songs").validate(songs => {
-						if (songs.length === 0) return true;
-						return songs[0].duration <= 10800;
-					}, "Max 3 hours per song.");
+					// this.schemas.playlist.path("songs").validate(songs => {
+					// 	if (songs.length === 0) return true;
+					// 	return songs[0].duration <= 10800;
+					// }, "Max 3 hours per song.");
 
 					this.schemas.playlist.index({ createdFor: 1, type: 1 }, { unique: true });