소스 검색

Added config option to hide automatically requested songs

Kristian Vos 3 년 전
부모
커밋
cacd6e8ef6
6개의 변경된 파일38개의 추가작업 그리고 14개의 파일을 삭제
  1. 2 1
      backend/config/template.json
  2. 1 1
      backend/index.js
  3. 10 4
      backend/logic/actions/playlists.js
  4. 5 1
      backend/logic/actions/stations.js
  5. 19 3
      backend/logic/songs.js
  6. 1 4
      backend/logic/youtube.js

+ 2 - 1
backend/config/template.json

@@ -7,6 +7,7 @@
 	"serverDomain": "http://localhost/backend",
 	"serverPort": 8080,
 	"registrationDisabled": true,
+	"hideAutomaticallyRequestedSongs": false,
 	"fancyConsole": true,
 	"apis": {
 		"youtube": {
@@ -88,5 +89,5 @@
 			]
 		}
 	},
-	"configVersion": 2
+	"configVersion": 3
 }

+ 1 - 1
backend/index.js

@@ -3,7 +3,7 @@ import "./loadEnvVariables.js";
 import util from "util";
 import config from "config";
 
-const REQUIRED_CONFIG_VERSION = 2;
+const REQUIRED_CONFIG_VERSION = 3;
 
 // eslint-disable-next-line
 Array.prototype.remove = function (item) {

+ 10 - 4
backend/logic/actions/playlists.js

@@ -891,7 +891,11 @@ export default {
 				(user, next) => {
 					SongsModule.runJob(
 						"ENSURE_SONG_EXISTS_BY_SONG_ID",
-						{ songId, userId: user.preferences.anonymousSongRequests ? null : session.userId },
+						{
+							songId,
+							userId: user.preferences.anonymousSongRequests ? null : session.userId,
+							automaticallyRequested: true
+						},
 						this
 					)
 						.then(response => {
@@ -1208,8 +1212,10 @@ export default {
 						});
 				},
 
-				(playlist, song, next) => {
-					const songName = song.artists ? `${song.title} by ${song.artists.join(", ")}` : song.title;
+				(playlist, youtubeSong, next) => {
+					const songName = youtubeSong.artists
+						? `${youtubeSong.title} by ${youtubeSong.artists.join(", ")}`
+						: youtubeSong.title;
 
 					if (playlist.displayName !== "Liked Songs" && playlist.displayName !== "Disliked Songs") {
 						ActivitiesModule.runJob("ADD_ACTIVITY", {
@@ -1217,7 +1223,7 @@ export default {
 							type: "playlist__remove_song",
 							payload: {
 								message: `Removed <songId>${songName}</songId> from playlist <playlistId>${playlist.displayName}</playlistId>`,
-								thumbnail: song.thumbnail,
+								thumbnail: youtubeSong.thumbnail,
 								playlistId,
 								songId
 							}

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

@@ -2835,7 +2835,11 @@ export default {
 				(station, user, next) => {
 					SongsModule.runJob(
 						"ENSURE_SONG_EXISTS_BY_SONG_ID",
-						{ songId, userId: user.preferences.anonymousSongRequests ? null : session.userId },
+						{
+							songId,
+							userId: user.preferences.anonymousSongRequests ? null : session.userId,
+							automaticallyRequested: true
+						},
 						this
 					)
 						.then(response => {

+ 19 - 3
backend/logic/songs.js

@@ -1,4 +1,5 @@
 import async from "async";
+import config from "config";
 import mongoose from "mongoose";
 import CoreClass from "../core";
 
@@ -159,6 +160,7 @@ class _SongsModule extends CoreClass {
 	 * @param {object} payload - an object containing the payload
 	 * @param {string} payload.songId - the youtube song id of the song we are trying to ensure is in the songs db
 	 * @param {string} payload.userId - the youtube song id of the song we are trying to ensure is in the songs db
+	 * @param {string} payload.automaticallyRequested - whether the song was automatically requested or not
 	 * @returns {Promise} - returns a promise (resolve, reject)
 	 */
 	ENSURE_SONG_EXISTS_BY_SONG_ID(payload) {
@@ -172,7 +174,7 @@ class _SongsModule extends CoreClass {
 					(song, next) => {
 						if (song && song.duration > 0) next(true, song);
 						else {
-							YouTubeModule.runJob("GET_SONG", { songId: payload.songId, userId: payload.userId }, this)
+							YouTubeModule.runJob("GET_SONG", { songId: payload.songId }, this)
 								.then(response => {
 									next(null, song, response.song);
 								})
@@ -198,7 +200,17 @@ class _SongsModule extends CoreClass {
 								return next(null, song);
 							});
 						} else {
-							const song = new SongsModule.SongModel({ ...youtubeSong });
+							const status =
+								payload.automaticallyRequested === false ||
+								config.get("hideAutomaticallyRequestedSongs") === false
+									? "unverified"
+									: "hidden";
+							const song = new SongsModule.SongModel({
+								...youtubeSong,
+								status,
+								requestedBy: payload.userId,
+								requestedAt: Date.now()
+							});
 							song.save({ validateBeforeSave: true }, err => {
 								if (err) return next(err, song);
 								return next(null, song);
@@ -779,7 +791,11 @@ class _SongsModule extends CoreClass {
 										},
 
 										next => {
-											SongsModule.runJob("ENSURE_SONG_EXISTS_BY_SONG_ID", { songId }, this)
+											SongsModule.runJob(
+												"ENSURE_SONG_EXISTS_BY_SONG_ID",
+												{ songId, automaticallyRequested: true },
+												this
+											)
 												.then(() => next())
 												.catch(next);
 											// SongsModule.runJob("REQUEST_SONG", { songId, userId: null }, this)

+ 1 - 4
backend/logic/youtube.js

@@ -170,10 +170,7 @@ class _YouTubeModule extends CoreClass {
 							songId: res.data.items[0].id,
 							title: res.data.items[0].snippet.title,
 							thumbnail: res.data.items[0].snippet.thumbnails.default.url,
-							duration,
-							status: "unverified",
-							requestedBy: payload.userId,
-							requestedAt: Date.now()
+							duration
 						};
 
 						return resolve({ song });