Ver Fonte

feat: added featured playlists backend, implemented on frontend and added documentation for it

Kristian Vos há 2 anos atrás
pai
commit
bff04b9751

+ 1 - 0
.wiki/Configuration.md

@@ -41,6 +41,7 @@ Location: `backend/config/default.json`
 | `cookie.secure` | Should be `true` for SSL connections, and `false` for normal http connections. |
 | `cookie.SIDname` | Name of the cookie stored for sessions. |
 | `blacklistedCommunityStationNames ` | Array of blacklisted community station names. |
+| `featuredPlaylists ` | Array of featured playlist id's. |
 | `skipConfigVersionCheck` | Skips checking if the config version is outdated or not. Should almost always be set to false. |
 | `skipDbDocumentsVersionCheck` | Skips checking if there are any DB documents outdated or not. Should almost always be set to false. |
 | `debug.stationIssue` | If set to `true` it will enable the `/debug_station` API endpoint on the backend, which provides information useful to debugging stations not skipping, as well as capure all jobs specified in `debug.captureJobs`. 

+ 6 - 3
backend/config/template.json

@@ -8,7 +8,7 @@
 	"serverPort": 8080,
 	"registrationDisabled": true,
 	"hideAutomaticallyRequestedSongs": false,
-    "hideAnonymousSongs": false,
+	"hideAnonymousSongs": false,
 	"sendDataRequestEmails": true,
 	"apis": {
 		"youtube": {
@@ -59,7 +59,10 @@
 		"secure": false,
 		"SIDname": "SID"
 	},
-	"blacklistedCommunityStationNames": ["musare"],
+	"blacklistedCommunityStationNames": [
+		"musare"
+	],
+	"featuredPlaylists": [],
 	"skipConfigVersionCheck": false,
 	"skipDbDocumentsVersionCheck": false,
 	"debug": {
@@ -92,5 +95,5 @@
 			]
 		}
 	},
-	"configVersion": 7
+	"configVersion": 8
 }

+ 1 - 1
backend/index.js

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

+ 60 - 0
backend/logic/actions/playlists.js

@@ -1,4 +1,5 @@
 import async from "async";
+import config from "config";
 
 import { isAdminRequired, isLoginRequired } from "./hooks";
 
@@ -530,6 +531,65 @@ export default {
 		);
 	}),
 
+	/**
+	 * Gets all playlists playlists
+	 *
+	 * @param {object} session - the session object automatically added by the websocket
+	 * @param {Function} cb - gets called with the result
+	 */
+	 indexFeaturedPlaylists: isLoginRequired(async function indexMyPlaylists(session, cb) {
+		const playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" }, this);
+
+		async.waterfall(
+			[
+				next => {
+					const featuredPlaylistIds = config.get("featuredPlaylists");
+					if (featuredPlaylistIds.length === 0) next(true, []);
+					else next(null, featuredPlaylistIds);
+				},
+
+				(featuredPlaylistIds, next) => {
+					const featuredPlaylists = [];
+					async.eachLimit(
+						featuredPlaylistIds,
+						1,
+						(playlistId, next) => {
+							PlaylistsModule.runJob("GET_PLAYLIST", { playlistId }, this)
+								.then(playlist => {
+									if (playlist.privacy === "public") featuredPlaylists.push(playlist);
+									next();
+								})
+								.catch(next);
+						},
+						err => {
+							next(err, featuredPlaylists);
+						}
+					);
+				}
+			],
+			async (err, playlists) => {
+				if (err && err !== true) {
+					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+					this.log(
+						"ERROR",
+						"PLAYLIST_INDEX_FEATURED",
+						`Indexing featured playlists failed. "${err}"`
+					);
+					return cb({ status: "error", message: err });
+				}
+				this.log(
+					"SUCCESS",
+					"PLAYLIST_INDEX_FEATURED",
+					`Successfully indexed featured playlists.`
+				);
+				return cb({
+					status: "success",
+					data: { playlists }
+				});
+			}
+		);
+	}),
+
 	/**
 	 * Creates a new private playlist
 	 *

+ 8 - 5
frontend/src/components/modals/ManageStation/Tabs/Playlists.vue

@@ -837,7 +837,8 @@ export default {
 				count: 0,
 				resultsLeft: 0,
 				results: []
-			}
+			},
+			featuredPlaylists: []
 		};
 	},
 	computed: {
@@ -847,10 +848,6 @@ export default {
 		nextPageResultsCount() {
 			return Math.min(this.search.pageSize, this.resultsLeftCount);
 		},
-		featuredPlaylists() {
-			if (this.search.results) return this.search.results.slice(0, 3); // TEMP
-			return [];
-		},
 		...mapState({
 			loggedIn: state => state.user.auth.loggedIn,
 			role: state => state.user.auth.role,
@@ -895,6 +892,12 @@ export default {
 				this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
 			});
 
+			this.socket.dispatch("playlists.indexFeaturedPlaylists", res => {
+				if (res.status === "success")
+					this.featuredPlaylists = res.data.playlists;
+				this.orderOfPlaylists = this.calculatePlaylistOrder(); // order in regards to the database
+			});
+
 			this.socket.dispatch(
 				`stations.getStationIncludedPlaylistsById`,
 				this.station._id,