Explorar o código

Added hide anonymous songs config option

Kristian Vos %!s(int64=3) %!d(string=hai) anos
pai
achega
97ddb5a4d2
Modificáronse 3 ficheiros con 13 adicións e 7 borrados
  1. 2 1
      backend/config/template.json
  2. 1 1
      backend/index.js
  3. 10 5
      backend/logic/songs.js

+ 2 - 1
backend/config/template.json

@@ -8,6 +8,7 @@
 	"serverPort": 8080,
 	"registrationDisabled": true,
 	"hideAutomaticallyRequestedSongs": false,
+    "hideAnonymousSongs": false,
 	"fancyConsole": true,
 	"apis": {
 		"youtube": {
@@ -89,5 +90,5 @@
 			]
 		}
 	},
-	"configVersion": 3
+	"configVersion": 4
 }

+ 1 - 1
backend/index.js

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

+ 10 - 5
backend/logic/songs.js

@@ -201,10 +201,11 @@ class _SongsModule extends CoreClass {
 							});
 						} else {
 							const status =
-								payload.automaticallyRequested === false ||
-								config.get("hideAutomaticallyRequestedSongs") === false
-									? "unverified"
-									: "hidden";
+								(!payload.userId && config.get("hideAnonymousSongs")) ||
+								(payload.automaticallyRequested && config.get("hideAutomaticallyRequestedSongs"))
+									? "hidden"
+									: "unverified";
+
 							const song = new SongsModule.SongModel({
 								...youtubeSong,
 								status,
@@ -599,6 +600,10 @@ class _SongsModule extends CoreClass {
 					(user, song, next) => {
 						if (song) return next("This song is already in the database.");
 						// TODO Add err object as first param of callback
+
+						const requestedBy = user.preferences.anonymousSongRequests ? null : userId;
+						const status = !requestedBy && config.get("hideAnonymousSongs") ? "hidden" : "unverified";
+
 						return YouTubeModule.runJob("GET_SONG", { songId }, this)
 							.then(response => {
 								const { song } = response;
@@ -608,7 +613,7 @@ class _SongsModule extends CoreClass {
 								song.explicit = false;
 								song.requestedBy = user.preferences.anonymousSongRequests ? null : userId;
 								song.requestedAt = requestedAt;
-								song.status = "unverified";
+								song.status = status;
 								next(null, song);
 							})
 							.catch(next);