Jelajahi Sumber

refactor: cleaned up some apis action comments and permissions

Kristian Vos 1 tahun lalu
induk
melakukan
106fd468fe
2 mengubah file dengan 12 tambahan dan 354 penghapusan
  1. 3 354
      backend/logic/actions/apis.js
  2. 9 0
      backend/logic/hooks/hasPermission.js

+ 3 - 354
backend/logic/actions/apis.js

@@ -118,357 +118,6 @@ export default {
 		);
 	}),
 
-	// /**
-	//  *
-	//  *
-	//  * @param session
-	//  * @param ISRC - the ISRC
-	//  * @param {Function} cb
-	//  */
-	// searchMusicBrainzISRC: useHasPermission("admin.view.spotify", function searchMusicBrainzISRC(session, ISRC, cb) {
-	// 	async.waterfall(
-	// 		[
-	// 			next => {
-	// 				if (!ISRC) {
-	// 					next("Invalid ISRC provided.");
-	// 					return;
-	// 				}
-
-	// 				CacheModule.runJob("HGET", { table: "musicbrainz-isrc-2", key: ISRC })
-	// 					.then(response => {
-	// 						if (response) next(null, response);
-	// 						else next(null, null);
-	// 					})
-	// 					.catch(err => {
-	// 						next(err);
-	// 					});
-	// 			},
-
-	// 			(body, next) => {
-	// 				if (body) {
-	// 					next(null, body);
-	// 					return;
-	// 				}
-
-	// 				const options = {
-	// 					params: { fmt: "json", inc: "url-rels+work-rels" },
-	// 					headers: {
-	// 						"User-Agent": "Musare/3.9.0-fork ( https://git.kvos.dev/kris/MusareFork )" // TODO set this in accordance to https://musicbrainz.org/doc/MusicBrainz_API/Rate_Limiting
-	// 					}
-	// 				};
-
-	// 				console.log("KRIS101", options, `https://musicbrainz.org/ws/2/isrc/${ISRC}`);
-
-	// 				axios
-	// 					.get(`https://musicbrainz.org/ws/2/isrc/${ISRC}`, options)
-	// 					.then(res => next(null, res.data))
-	// 					.catch(err => next(err));
-	// 			},
-
-	// 			(body, next) => {
-	// 				console.log("KRIS222", body);
-
-	// 				CacheModule.runJob("HSET", { table: "musicbrainz-isrc-2", key: ISRC, value: body })
-	// 					.then(() => {})
-	// 					.catch(() => {});
-
-	// 				next(null, body);
-	// 			},
-
-	// 			(body, next) => {
-	// 				const response = {};
-
-	// 				const recordingUrls = Array.from(
-	// 					new Set(
-	// 						body.recordings
-	// 							.map(recording =>
-	// 								recording.relations
-	// 									.filter(
-	// 										relation =>
-	// 											relation["target-type"] === "url" &&
-	// 											relation.url &&
-	// 											// relation["type-id"] === "7e41ef12-a124-4324-afdb-fdbae687a89c" &&
-	// 											(relation.url.resource.indexOf("youtu.be") !== -1 ||
-	// 												relation.url.resource.indexOf("youtube.com") !== -1 ||
-	// 												relation.url.resource.indexOf("soundcloud.com") !== -1)
-	// 									)
-	// 									.map(relation => relation.url.resource)
-	// 							)
-	// 							.flat()
-	// 					)
-	// 				);
-
-	// 				const workIds = Array.from(
-	// 					new Set(
-	// 						body.recordings
-	// 							.map(recording =>
-	// 								recording.relations
-	// 									.filter(relation => relation["target-type"] === "work" && relation.work)
-	// 									.map(relation => relation.work.id)
-	// 							)
-	// 							.flat()
-	// 					)
-	// 				);
-
-	// 				response.recordingUrls = recordingUrls;
-	// 				response.workIds = workIds;
-
-	// 				response.raw = body;
-
-	// 				next(null, response);
-	// 			}
-	// 		],
-	// 		async (err, response) => {
-	// 			if (err && err !== true) {
-	// 				err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
-	// 				this.log(
-	// 					"ERROR",
-	// 					"APIS_SEARCH_MUSICBRAINZ_ISRC",
-	// 					`Searching MusicBrainz ISRC failed with ISRC "${ISRC}". "${err}"`
-	// 				);
-	// 				return cb({ status: "error", message: err });
-	// 			}
-	// 			this.log(
-	// 				"SUCCESS",
-	// 				"APIS_SEARCH_MUSICBRAINZ_ISRC",
-	// 				`User "${session.userId}" searched MusicBrainz ISRC succesfully for ISRC "${ISRC}".`
-	// 			);
-	// 			return cb({
-	// 				status: "success",
-	// 				data: {
-	// 					response
-	// 				}
-	// 			});
-	// 		}
-	// 	);
-	// }),
-
-	// /**
-	//  *
-	//  *
-	//  * @param session
-	//  * @param trackId - the trackId
-	//  * @param {Function} cb
-	//  */
-	// searchWikidataBySpotifyTrackId: useHasPermission(
-	// 	"admin.view.spotify",
-	// 	function searchWikidataBySpotifyTrackId(session, trackId, cb) {
-	// 		async.waterfall(
-	// 			[
-	// 				next => {
-	// 					if (!trackId) {
-	// 						next("Invalid trackId provided.");
-	// 						return;
-	// 					}
-
-	// 					CacheModule.runJob("HGET", { table: "wikidata-spotify-track", key: trackId })
-	// 						.then(response => {
-	// 							if (response) next(null, response);
-	// 							else next(null, null);
-	// 						})
-	// 						.catch(err => {
-	// 							console.log("WOW", err);
-	// 							next(err);
-	// 						});
-	// 				},
-
-	// 				(body, next) => {
-	// 					if (body) {
-	// 						next(null, body);
-	// 						return;
-	// 					}
-
-	// 					// const options = {
-	// 					// 	params: { fmt: "json", inc: "url-rels" },
-	// 					// 	headers: {
-	// 					// 		"User-Agent": "Musare/3.9.0-fork ( https://git.kvos.dev/kris/MusareFork )" // TODO set this in accordance to https://musicbrainz.org/doc/MusicBrainz_API/Rate_Limiting
-	// 					// 	}
-	// 					// };
-
-	// 					// axios
-	// 					// 	.get(`https://musicbrainz.org/ws/2/isrc/${ISRC}`, options)
-	// 					// 	.then(res => next(null, res.data))
-	// 					// 	.catch(err => next(err));
-	// 				},
-
-	// 				(body, next) => {
-	// 					CacheModule.runJob("HSET", { table: "musicbrainz-isrc", key: ISRC, value: body })
-	// 						.then(() => {})
-	// 						.catch(() => {});
-
-	// 					next(null, body);
-	// 				},
-
-	// 				(body, next) => {
-	// 					const response = {};
-
-	// 					const recordingUrls = Array.from(
-	// 						new Set(
-	// 							body.recordings
-	// 								.map(recording =>
-	// 									recording.relations
-	// 										.filter(
-	// 											relation =>
-	// 												relation["target-type"] === "url" &&
-	// 												relation.url &&
-	// 												// relation["type-id"] === "7e41ef12-a124-4324-afdb-fdbae687a89c" &&
-	// 												(relation.url.resource.indexOf("youtu.be") !== -1 ||
-	// 													relation.url.resource.indexOf("youtube.com") !== -1 ||
-	// 													relation.url.resource.indexOf("soundcloud.com") !== -1)
-	// 										)
-	// 										.map(relation => relation.url.resource)
-	// 								)
-	// 								.flat()
-	// 						)
-	// 					);
-
-	// 					response.recordingUrls = recordingUrls;
-
-	// 					response.raw = body;
-
-	// 					next(null, response);
-	// 				}
-	// 			],
-	// 			async (err, response) => {
-	// 				if (err && err !== true) {
-	// 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
-	// 					this.log(
-	// 						"ERROR",
-	// 						"APIS_SEARCH_TODO",
-	// 						`Searching MusicBrainz ISRC failed with ISRC "${ISRC}". "${err}"`
-	// 					);
-	// 					return cb({ status: "error", message: err });
-	// 				}
-	// 				this.log(
-	// 					"SUCCESS",
-	// 					"APIS_SEARCH_TODO",
-	// 					`User "${session.userId}" searched MusicBrainz ISRC succesfully for ISRC "${ISRC}".`
-	// 				);
-	// 				return cb({
-	// 					status: "success",
-	// 					data: {
-	// 						response
-	// 					}
-	// 				});
-	// 			}
-	// 		);
-	// 	}
-	// ),
-
-	// /**
-	//  *
-	//  *
-	//  * @param session
-	//  * @param trackId - the trackId
-	//  * @param {Function} cb
-	//  */
-	// searchWikidataByMusicBrainzWorkId: useHasPermission(
-	// 	"admin.view.spotify",
-	// 	function searchWikidataByMusicBrainzWorkId(session, workId, cb) {
-	// 		async.waterfall(
-	// 			[
-	// 				next => {
-	// 					if (!workId) {
-	// 						next("Invalid workId provided.");
-	// 						return;
-	// 					}
-
-	// 					CacheModule.runJob("HGET", { table: "wikidata-musicbrainz-work", key: workId })
-	// 						.then(response => {
-	// 							if (response) next(null, response);
-	// 							else next(null, null);
-	// 						})
-	// 						.catch(err => {
-	// 							next(err);
-	// 						});
-	// 				},
-
-	// 				(body, next) => {
-	// 					if (body) {
-	// 						next(null, body);
-	// 						return;
-	// 					}
-
-	// 					const endpointUrl = "https://query.wikidata.org/sparql";
-	// 					const sparqlQuery = `SELECT DISTINCT ?item ?itemLabel ?YouTube_video_ID WHERE {
-	// 					SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
-	// 					{
-	// 						SELECT DISTINCT ?item WHERE {
-	// 						?item p:P435 ?statement0.
-	// 						?statement0 ps:P435 "${workId}".
-	// 						}
-	// 						LIMIT 100
-	// 					}
-	// 					OPTIONAL { ?item wdt:P1651 ?YouTube_video_ID. }
-	// 					}`;
-	// 					// OPTIONAL { ?item wdt:P3040 ?SoundCloud_track_ID. }
-
-	// const options = {
-	// 	params: { query: sparqlQuery },
-	// 	headers: {
-	// 		Accept: "application/sparql-results+json"
-	// 	}
-	// };
-
-	// axios
-	// 	.get(endpointUrl, options)
-	// 	.then(res => next(null, res.data))
-	// 	.catch(err => next(err));
-	// 				},
-
-	// 				(body, next) => {
-	// 					CacheModule.runJob("HSET", { table: "wikidata-musicbrainz-work", key: workId, value: body })
-	// 						.then(() => {})
-	// 						.catch(() => {});
-
-	// 					next(null, body);
-	// 				},
-
-	// 				(body, next) => {
-	// 					const response = {};
-
-	// 					const youtubeIds = Array.from(
-	// 						new Set(
-	// 							body.results.bindings
-	// 								.filter(binding => !!binding.YouTube_video_ID)
-	// 								.map(binding => binding.YouTube_video_ID.value)
-	// 						)
-	// 					);
-	// 					// const soundcloudIds = Array.from(new Set(body.results.bindings.filter(binding => !!binding["SoundCloud_track_ID"]).map(binding => binding["SoundCloud_track_ID"].value)))
-
-	// 					response.youtubeIds = youtubeIds;
-
-	// 					response.raw = body;
-
-	// 					next(null, response);
-	// 				}
-	// 			],
-	// 			async (err, response) => {
-	// 				if (err && err !== true) {
-	// 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
-	// 					this.log(
-	// 						"ERROR",
-	// 						"APIS_SEARCH_TODO",
-	// 						`Searching MusicBrainz ISRC failed with ISRC "${workId}". "${err}"`
-	// 					);
-	// 					return cb({ status: "error", message: err });
-	// 				}
-	// 				this.log(
-	// 					"SUCCESS",
-	// 					"APIS_SEARCH_TODO",
-	// 					`User "${session.userId}" searched MusicBrainz ISRC succesfully for ISRC "${workId}".`
-	// 				);
-	// 				return cb({
-	// 					status: "success",
-	// 					data: {
-	// 						response
-	// 					}
-	// 				});
-	// 			}
-	// 		);
-	// 	}
-	// ),
-
 	/**
 	 *
 	 *
@@ -477,7 +126,7 @@ export default {
 	 * @param {Function} cb
 	 */
 	getAlternativeMediaSourcesForTracks: useHasPermission(
-		"admin.view.spotify",
+		"spotify.getAlternativeMediaSourcesForTracks",
 		function getAlternativeMediaSourcesForTracks(session, mediaSources, collectAlternativeMediaSourcesOrigins, cb) {
 			async.waterfall(
 				[
@@ -543,7 +192,7 @@ export default {
 	 * @param {Function} cb
 	 */
 	getAlternativeAlbumSourcesForAlbums: useHasPermission(
-		"admin.view.spotify",
+		"spotify.getAlternativeAlbumSourcesForAlbums",
 		function getAlternativeAlbumSourcesForAlbums(session, albumIds, collectAlternativeAlbumSourcesOrigins, cb) {
 			async.waterfall(
 				[
@@ -611,7 +260,7 @@ export default {
 	 * @param {Function} cb
 	 */
 	getAlternativeArtistSourcesForArtists: useHasPermission(
-		"admin.view.spotify",
+		"spotify.getAlternativeArtistSourcesForArtists",
 		function getAlternativeArtistSourcesForArtists(session, artistIds, collectAlternativeArtistSourcesOrigins, cb) {
 			async.waterfall(
 				[

+ 9 - 0
backend/logic/hooks/hasPermission.js

@@ -127,6 +127,15 @@ if (config.get("experimental.spotify")) {
 
 	permissions.moderator["spotify.getArtistsFromIds"] = true;
 	permissions.admin["spotify.getArtistsFromIds"] = true;
+
+	permissions.moderator["spotify.getAlternativeArtistSourcesForArtists"] = true;
+	permissions.admin["spotify.getAlternativeArtistSourcesForArtists"] = true;
+
+	permissions.moderator["spotify.getAlternativeAlbumSourcesForAlbums"] = true;
+	permissions.admin["spotify.getAlternativeAlbumSourcesForAlbums"] = true;
+
+	permissions.moderator["spotify.getAlternativeMediaSourcesForTracks"] = true;
+	permissions.admin["spotify.getAlternativeMediaSourcesForTracks"] = true;
 }
 
 export const hasPermission = async (permission, session, stationId) => {