Ver Fonte

feat(Station): Per user request limit

Owen Diffey há 3 anos atrás
pai
commit
2c675d386f

+ 15 - 0
backend/logic/actions/stations.js

@@ -1917,6 +1917,21 @@ export default {
 				(song, station, next) => {
 					song.requestedBy = session.userId;
 					song.requestedAt = Date.now();
+					return next(null, song, station);
+				},
+
+				(song, station, next) => {
+					if (station.queue.length === 0) return next(null, song);
+					let totalSongs = 0;
+					station.queue.forEach(song => {
+						if (session.userId === song.requestedBy) {
+							totalSongs += 1;
+						}
+					});
+
+					if (totalSongs > station.requests.limit)
+						return next(`The max amount of songs per user is ${station.requests.limit}.`);
+
 					return next(null, song);
 				},
 

+ 2 - 1
backend/logic/db/schemas/station.js

@@ -42,7 +42,8 @@ export default {
 	],
 	owner: { type: String },
 	requests: {
-		enabled: { type: Boolean, default: true }
+		enabled: { type: Boolean, default: true },
+		limit: { type: Number, min: 1, max: 50, default: 3 }
 	},
 	playMode: { type: String, enum: ["random", "sequential"], default: "random" },
 	theme: { type: String, enum: ["blue", "purple", "teal", "orange", "red"], default: "blue" },

+ 7 - 3
frontend/src/components/Request.vue

@@ -939,7 +939,7 @@ export default {
 			if (
 				!this.autoRequestLock &&
 				this.songsList.length < 50 &&
-				this.currentUserQueueSongs < 3 &&
+				this.currentUserQueueSongs < this.station.requests.limit &&
 				this.autoRequest.length > 0
 			) {
 				const selectedPlaylist =
@@ -954,13 +954,13 @@ export default {
 							)
 						];
 					if (selectedSong.youtubeId) {
-						this.autoRequestLock = true;
+						this.updateAutoRequestLock(true);
 						this.socket.dispatch(
 							"stations.addToQueue",
 							this.station._id,
 							selectedSong.youtubeId,
 							data => {
-								this.autoRequestLock = false;
+								this.updateAutoRequestLock(false);
 								if (data.status !== "success")
 									this.autoRequestSong();
 							}
@@ -989,6 +989,10 @@ export default {
 			);
 		},
 		...mapActions("station", ["updateAutoRequest"]),
+		...mapActions("station", [
+			"updateAutoRequest",
+			"updateAutoRequestLock"
+		]),
 		...mapActions("modalVisibility", ["openModal"]),
 		...mapActions("user/playlists", ["editPlaylist", "setPlaylists"])
 	}

+ 19 - 4
frontend/src/components/modals/ManageStation/Tabs/Settings.vue

@@ -81,7 +81,7 @@
 					</p>
 				</div>
 
-				<div v-if="local.requests.enabled" class="control is-expanded">
+				<div v-if="local.requests.enabled" class="small-section">
 					<label class="label">Minimum access</label>
 					<div class="control is-expanded select">
 						<select v-model="local.requests.access">
@@ -90,6 +90,19 @@
 						</select>
 					</div>
 				</div>
+
+				<div v-if="local.requests.enabled" class="small-section">
+					<label class="label">Per user request limit</label>
+					<div class="control is-expanded">
+						<input
+							class="input"
+							type="number"
+							min="1"
+							max="50"
+							v-model="local.requests.limit"
+						/>
+					</div>
+				</div>
 			</div>
 
 			<hr class="section-horizontal-rule" />
@@ -140,7 +153,7 @@
 							class="input"
 							type="number"
 							min="1"
-							max="30"
+							max="50"
 							v-model="local.autofill.limit"
 						/>
 					</div>
@@ -184,7 +197,8 @@ export default {
 				privacy: "private",
 				requests: {
 					enabled: true,
-					access: "owner"
+					access: "owner",
+					limit: 3
 				},
 				autofill: {
 					enabled: true,
@@ -208,7 +222,8 @@ export default {
 			...this.station,
 			requests: {
 				enabled: this.station.requests.enabled,
-				access: "owner"
+				access: "owner",
+				limit: this.station.requests.limit
 			},
 			autofill: {
 				enabled: true,