Browse Source

Changed some things to hopefully fix bug with skipDuration on station page

Kristian Vos 3 years ago
parent
commit
f94c31af06

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

@@ -3042,13 +3042,14 @@ export default {
 					)
 						.then(response => {
 							const { song } = response;
-							const { _id, title, artists, thumbnail, duration, status } = song;
+							const { _id, title, skipDuration, artists, thumbnail, duration, status } = song;
 							next(
 								null,
 								{
 									_id,
 									youtubeId,
 									title,
+									skipDuration,
 									artists,
 									thumbnail,
 									duration,

+ 40 - 0
backend/logic/songs.js

@@ -155,6 +155,46 @@ class _SongsModule extends CoreClass {
 		);
 	}
 
+	/**
+	 * Gets songs by id from Mongo
+	 *
+	 * @param {object} payload - object containing the payload
+	 * @param {string} payload.songIds - the ids of the songs we are trying to get
+	 * @param {string} payload.properties - the properties to return
+	 * @returns {Promise} - returns a promise (resolve, reject)
+	 */
+	GET_SONGS(payload) {
+		return new Promise((resolve, reject) =>
+			async.waterfall(
+				[
+					next => {
+						if (!payload.songIds.every(songId => mongoose.Types.ObjectId.isValid(songId)))
+							return next("One or more songIds are not a valid ObjectId.");
+						next();
+					},
+
+					next => {
+						const includeProperties = {};
+						payload.properties.forEach(property => {
+							includeProperties[property] = true;
+						});
+						return SongsModule.SongModel.find(
+							{
+								_id: { $in: payload.songIds }
+							},
+							includeProperties,
+							next
+						);
+					}
+				],
+				(err, songs) => {
+					if (err && err !== true) return reject(new Error(err));
+					return resolve({ songs });
+				}
+			)
+		);
+	}
+
 	/**
 	 * Makes sure that if a song is not currently in the songs db, to add it
 	 *

+ 28 - 0
backend/logic/stations.js

@@ -541,6 +541,34 @@ class _StationsModule extends CoreClass {
 							if (indexOfLastSong !== -1) currentSongIndex = indexOfLastSong;
 						}
 
+						next(null, currentSongs, songsToAdd, currentSongIndex);
+					},
+
+					(currentSongs, songsToAdd, currentSongIndex, next) => {
+						SongsModule.runJob("GET_SONGS", {
+							songIds: songsToAdd.map(song => song._id),
+							properties: [
+								"youtubeId",
+								"title",
+								"duration",
+								"skipDuration",
+								"artists",
+								"thumbnail",
+								"status"
+							]
+						})
+							.then(response => {
+								const newSongsToAdd = songsToAdd.map(song => {
+									return response.songs.find(
+										newSong => newSong._id.toString() === song._id.toString()
+									);
+								});
+								next(null, currentSongs, newSongsToAdd, currentSongIndex);
+							})
+							.catch(err => next(err));
+					},
+
+					(currentSongs, songsToAdd, currentSongIndex, next) => {
 						const newPlaylist = [...currentSongs, ...songsToAdd].map(song => {
 							if (!song._id) song._id = null;
 							return song;

+ 5 - 0
frontend/src/pages/Station/index.vue

@@ -1120,6 +1120,11 @@ export default {
 				pausedAt
 			} = data;
 
+			if (!currentSong.skipDuration || currentSong.skipDuration < 0)
+				currentSong.skipDuration = 0;
+			if (!currentSong.duration || currentSong.duration < 0)
+				currentSong.duration = 0;
+
 			this.updateCurrentSong(currentSong || {});
 
 			let nextSong = null;