Browse Source

feat: added experimental option to add songs earlier in the queue

Kristian Vos 1 year ago
parent
commit
d9ad1b300c
3 changed files with 55 additions and 5 deletions
  1. 15 1
      backend/config/template.json
  2. 34 3
      backend/logic/stations.js
  3. 6 1
      frontend/dist/config/template.json

+ 15 - 1
backend/config/template.json

@@ -114,5 +114,19 @@
 			]
 		}
 	},
-	"configVersion": 11
+	"configVersion": 11,
+	"experimental": {
+		"weight_stations": [
+			"STATION_ID"
+		],
+		"queue_autofill_skip_last_x_played": {
+			"STATION_ID": 5
+		},
+		"queue_autofill_skip_played_in_last_x_minutes": {
+			"STATION_ID": 5
+		},
+		"queue_add_before_autofilled": {
+			"STATION_ID": true
+		}
+	}
 }

+ 34 - 3
backend/logic/stations.js

@@ -1895,14 +1895,14 @@ class _StationsModule extends CoreClass {
 					(song, station, next) => {
 						song.requestedBy = requestUser;
 						song.requestedAt = Date.now();
-						if (station.queue.length === 0) return next(null, song);
+						if (station.queue.length === 0) return next(null, song, station);
 						if (
 							requestUser &&
 							station.queue.filter(queueSong => queueSong.requestedBy === song.requestedBy).length >=
 								station.requests.limit
 						)
 							return next(`The max amount of songs per user is ${station.requests.limit}.`);
-						return next(null, song);
+						return next(null, song, station);
 					},
 
 					// (song, station, next) => {
@@ -1952,7 +1952,38 @@ class _StationsModule extends CoreClass {
 					// 	return next(null, song);
 					// },
 
-					(song, next) => {
+					(song, station, next) => {
+						if (config.has(`experimental.queue_add_before_autofilled`)) {
+							const queueAddBeforeAutofilled = config.get(`experimental.queue_add_before_autofilled`);
+
+							if (
+								queueAddBeforeAutofilled === true ||
+								queueAddBeforeAutofilled.indexOf(stationId) !== -1
+							) {
+								let position = station.queue.length;
+
+								if (station.autofill.enabled && station.queue.length >= station.autofill.limit) {
+									position = -station.autofill.limit;
+								}
+
+								StationsModule.stationModel.updateOne(
+									{ _id: stationId },
+									{
+										$push: {
+											queue: {
+												$each: [song],
+												$position: position
+											}
+										}
+									},
+									{ runValidators: true },
+									next
+								);
+
+								return;
+							}
+						}
+
 						StationsModule.stationModel.updateOne(
 							{ _id: stationId },
 							{ $push: { queue: song } },

+ 6 - 1
frontend/dist/config/template.json

@@ -46,5 +46,10 @@
 		"version": true
 	},
 	"skipConfigVersionCheck": false,
-	"configVersion": 13
+	"configVersion": 13,
+	"experimental": {
+		"changable_listen_mode": [
+			"STATION_ID"
+		]
+	}
 }