Browse Source

fix: stations are created with currentSong as an empty object instead of null

Kristian Vos 11 months ago
parent
commit
ff6b95abd1
2 changed files with 17 additions and 3 deletions
  1. 16 2
      backend/logic/actions/stations.js
  2. 1 1
      backend/logic/stations.js

+ 16 - 2
backend/logic/actions/stations.js

@@ -1854,12 +1854,26 @@ export default {
 								type,
 								privacy: "private",
 								owner: session.userId,
-								queue: [],
-								currentSong: null
+								queue: []
 							},
 							next
 						);
 					}
+				},
+
+				// This extra step is needed because Mongoose decides to create an object with empty arrays for currentSong for some reason
+				(station, next) => {
+					stationModel.updateOne(
+						{ _id: station._id },
+						{
+							$set: {
+								currentSong: null
+							}
+						},
+						err => {
+							next(err, station);
+						}
+					);
 				}
 			],
 			async (err, station) => {

+ 1 - 1
backend/logic/stations.js

@@ -309,7 +309,7 @@ class _StationsModule extends CoreClass {
 					(station, next) => {
 						// A current song is invalid if it isn't allowed to be played. Spotify songs can never be played, and SoundCloud songs can't be played if SoundCloud isn't enabled
 						let currentSongIsInvalid = false;
-						if (station.currentSong) {
+						if (station.currentSong && station.currentSong.mediaSource) {
 							if (station.currentSong.mediaSource.startsWith("spotify:")) currentSongIsInvalid = true;
 							if (
 								station.currentSong.mediaSource.startsWith("soundcloud:") &&