2 Commits 9b06e31761 ... 5bc14cd82e

Author SHA1 Message Date
  Kristian Vos 5bc14cd82e chore: lint fixes 1 month ago
  Kristian Vos 9b06e31761 chore: lint fixes 1 month ago

+ 1 - 3
backend/logic/actions/albums.js

@@ -7,8 +7,6 @@ import moduleManager from "../../index";
 
 const DBModule = moduleManager.modules.db;
 const UtilsModule = moduleManager.modules.utils;
-const WSModule = moduleManager.modules.ws;
-const CacheModule = moduleManager.modules.cache;
 
 export default {
 	/**
@@ -113,5 +111,5 @@ export default {
 				}
 			);
 		}
-	),
+	)
 };

+ 66 - 55
backend/logic/actions/artists.js

@@ -158,7 +158,8 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					if (data?.musicbrainzData?.id !== data?.musicbrainzIdentifier) return next("MusicBrainz data must match the provided identifier.");
+					if (data?.musicbrainzData?.id !== data?.musicbrainzIdentifier)
+						return next("MusicBrainz data must match the provided identifier.");
 					return next();
 				},
 				next => {
@@ -229,7 +230,8 @@ export default {
 			[
 				next => {
 					if (!artistId) return next("Please provide an artist item id to update.");
-					if (item?.musicbrainzData?.id !== item?.musicbrainzIdentifier) return next("MusicBrainz data must match the provided identifier.");
+					if (item?.musicbrainzData?.id !== item?.musicbrainzIdentifier)
+						return next("MusicBrainz data must match the provided identifier.");
 					return next();
 				},
 
@@ -263,66 +265,75 @@ export default {
 		);
 	}),
 
-	getMusicbrainzArtist: useHasPermission("artists.update", async function getMusicbrainzArtist(session, musicbrainzIdentifier, cb) {
-		const ArtistApiResponse = await MusicBrainzModule.runJob(
-			"API_CALL",
-			{
-				url: `https://musicbrainz.org/ws/2/artist/${musicbrainzIdentifier}/`,
-				params: {
-					fmt: "json",
-					inc: "aliases"
-				}
-			},
-			this
-		);
+	getMusicbrainzArtist: useHasPermission(
+		"artists.update",
+		async function getMusicbrainzArtist(session, musicbrainzIdentifier, cb) {
+			const ArtistApiResponse = await MusicBrainzModule.runJob(
+				"API_CALL",
+				{
+					url: `https://musicbrainz.org/ws/2/artist/${musicbrainzIdentifier}/`,
+					params: {
+						fmt: "json",
+						inc: "aliases"
+					}
+				},
+				this
+			);
 
-		return cb({
-			data: ArtistApiResponse,
-		});
-	}),
+			return cb({
+				data: ArtistApiResponse
+			});
+		}
+	),
 
-	getMusicbrainzRelatedUrls: useHasPermission("artists.update", async function getMusicbrainzRelatedUrls(session, musicbrainzIdentifier, cb) {
-		const ArtistApiResponse = await MusicBrainzModule.runJob(
-			"API_CALL",
-			{
-				url: `https://musicbrainz.org/ws/2/artist/${musicbrainzIdentifier}/`,
-				params: {
-					fmt: "json",
-					inc: "url-rels"
-				}
-			},
-			this
-		);
+	getMusicbrainzRelatedUrls: useHasPermission(
+		"artists.update",
+		async function getMusicbrainzRelatedUrls(session, musicbrainzIdentifier, cb) {
+			const ArtistApiResponse = await MusicBrainzModule.runJob(
+				"API_CALL",
+				{
+					url: `https://musicbrainz.org/ws/2/artist/${musicbrainzIdentifier}/`,
+					params: {
+						fmt: "json",
+						inc: "url-rels"
+					}
+				},
+				this
+			);
 
-		return cb({
-			data: ArtistApiResponse,
-		});
-	}),
+			return cb({
+				data: ArtistApiResponse
+			});
+		}
+	),
 
 	getIdFromUrl: useHasPermission("artists.update", async function getIdFromUrl(session, type, url, cb) {
 		if (type === "youtube") {
 			YouTubeModule.runJob("GET_CHANNEL_ID", {
 				url,
-				disableSearch: false,
-			}).then(({ channelId }) => {
-				if (channelId) {
-					cb({
-						status: "success",
-						channelId,
-					});
-				} else {
-					cb({
-						status: "error",
-						message: "Playlist id not found",
-					});
-				}
-			}).catch(async err => {
-				err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
-				cb({ status: "error", message: err });
+				disableSearch: false
+			})
+				.then(({ channelId }) => {
+					if (channelId) {
+						cb({
+							status: "success",
+							channelId
+						});
+					} else {
+						cb({
+							status: "error",
+							message: "Playlist id not found"
+						});
+					}
+				})
+				.catch(async err => {
+					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+					cb({ status: "error", message: err });
+				});
+		} else
+			cb({
+				status: "error",
+				message: "Invalid type"
 			});
-		} else cb({
-			status: "error",
-			message: "Invalid type"
-		});
-	}),
+	})
 };

+ 1 - 1
backend/logic/actions/index.js

@@ -33,5 +33,5 @@ export default {
 	spotify,
 	media,
 	artists,
-	albums,
+	albums
 };

+ 1 - 1
backend/logic/actions/playlists.js

@@ -1871,7 +1871,7 @@ export default {
 									url,
 									musicOnly,
 									disableSearch: !isAdmin,
-									max,
+									max
 								},
 								this
 							)

+ 3 - 3
backend/logic/db/index.js

@@ -27,7 +27,7 @@ const REQUIRED_DOCUMENT_VERSIONS = {
 	spotifyArtist: 1,
 	genericApiRequest: 1,
 	artist: 1,
-	album: 1,
+	album: 1
 };
 
 const regex = {
@@ -92,7 +92,7 @@ class _DBModule extends CoreClass {
 						spotifyArtist: {},
 						genericApiRequest: {},
 						artist: {},
-						album: {},
+						album: {}
 					};
 
 					const importSchema = schemaName =>
@@ -150,7 +150,7 @@ class _DBModule extends CoreClass {
 						spotifyArtist: mongoose.model("spotifyArtist", this.schemas.spotifyArtist),
 						genericApiRequest: mongoose.model("genericApiRequest", this.schemas.genericApiRequest),
 						artist: mongoose.model("artist", this.schemas.artist),
-						album: mongoose.model("album", this.schemas.album),
+						album: mongoose.model("album", this.schemas.album)
 					};
 
 					mongoose.connection.on("error", err => {

+ 3 - 3
backend/logic/db/schemas/artist.js

@@ -3,19 +3,19 @@ export default {
 	youtubeChannels: [
 		{
 			youtubeChannelId: { type: String },
-			comment: { type: String },
+			comment: { type: String }
 		}
 	],
 	spotifyArtists: [
 		{
 			spotifyArtistId: { type: String },
-			comment: { type: String },
+			comment: { type: String }
 		}
 	],
 	soundcloudArtists: [
 		{
 			soundcloudArtistId: { type: String },
-			comment: { type: String },
+			comment: { type: String }
 		}
 	],
 	musicbrainzIdentifier: { type: String, required: true },

+ 46 - 53
backend/logic/youtube.js

@@ -467,7 +467,6 @@ class _YouTubeModule extends CoreClass {
 
 	/**
 	 * Gets the id of the channel from a username
-	 *
 	 * @param {object} payload - object that contains the payload
 	 * @param {string} payload.username - the username of the YouTube channel
 	 * @returns {Promise} - returns promise (reject, resolve)
@@ -898,7 +897,6 @@ class _YouTubeModule extends CoreClass {
 
 	/**
 	 * Returns the channel ID from a provided URL
-	 *
 	 * @param {object} payload - object that contains the payload
 	 * @param {boolean} payload.disableSearch - whether to allow searching for custom url/username
 	 * @param {string} payload.url - the url of the YouTube channel
@@ -925,14 +923,15 @@ class _YouTubeModule extends CoreClass {
 			async.waterfall(
 				[
 					next => {
-						if (channelId) return next(true, channelId);
-						if (!channelUsername) return next(null, true, null);
-
-						YouTubeModule.runJob("GET_CHANNEL_ID_FROM_USERNAME", { username: channelUsername, }, this)
-							.then(({ channelId }) => {
-								next(null, null, channelId)
-							})
-							.catch(next);
+						if (channelId) next(true, channelId);
+						else if (!channelUsername) next(null, true, null);
+						else {
+							YouTubeModule.runJob("GET_CHANNEL_ID_FROM_USERNAME", { username: channelUsername }, this)
+								.then(({ channelId }) => {
+									next(null, null, channelId);
+								})
+								.catch(next);
+						}
 					},
 
 					(getUsernameFromCustomUrl, channelId, next) => {
@@ -940,6 +939,7 @@ class _YouTubeModule extends CoreClass {
 
 						if (disableSearch)
 							return next(
+								// eslint-disable-next-line
 								"You are not allowed to look up this type of YouTube channel URL. Please provide a channel URL with the channel ID in it."
 							);
 						const payload = {};
@@ -952,7 +952,7 @@ class _YouTubeModule extends CoreClass {
 								next(null, channelId);
 							})
 							.catch(err => next(err));
-					},
+					}
 				],
 				(err, channelId) => {
 					console.log(111, err, channelId);
@@ -1041,14 +1041,16 @@ class _YouTubeModule extends CoreClass {
 
 						async.whilst(
 							next => {
-								if (payload.max > 0 && songs.length > payload.max) return next(null, false);
-								YouTubeModule.log(
-									"INFO",
-									`Getting channel progress for job (${this.toString()}): ${
-										songs.length
-									} songs gotten so far. Is there a next page: ${nextPageToken !== undefined}.`
-								);
-								next(null, nextPageToken !== undefined);
+								if (payload.max > 0 && songs.length > payload.max) next(null, false);
+								else {
+									YouTubeModule.log(
+										"INFO",
+										`Getting channel progress for job (${this.toString()}): ${
+											songs.length
+										} songs gotten so far. Is there a next page: ${nextPageToken !== undefined}.`
+									);
+									next(null, nextPageToken !== undefined);
+								}
 							},
 							next => {
 								// Add 250ms delay between each job request
@@ -1653,44 +1655,41 @@ class _YouTubeModule extends CoreClass {
 			stats.failedVideoIds = [];
 			stats.successfulVideoIds = existingYoutubeIds;
 		}
-		
 
 		if (!replaceExisting) {
 			if (!createMissing) {
 				return {
 					...stats,
-					videos: existingVideos,
-				}
+					videos: existingVideos
+				};
 			}
 			if (identifiers.length === existingVideos.length || youtubeIds.length === 0) {
 				return {
 					...stats,
 					videos: existingVideos
-				}
+				};
 			}
 
 			const missingYoutubeIds = youtubeIds.filter(youtubeId => existingYoutubeIds.indexOf(youtubeId) === -1);
 
-			if (missingYoutubeIds.length === 0) return {
-				...stats,
-				videos: existingVideos,
-			}
+			if (missingYoutubeIds.length === 0)
+				return {
+					...stats,
+					videos: existingVideos
+				};
 
 			const newVideos = await getVideosFromYoutubeIds(missingYoutubeIds);
 
 			await YouTubeModule.runJob("CREATE_VIDEOS", { youtubeVideos: newVideos }, this);
 
 			stats.successful += newVideos.length;
-			stats.successfulVideoIds = [
-				...stats.successfulVideoIds,
-				...newVideos.map(newVideo => newVideo.youtubeId),
-			];
+			stats.successfulVideoIds = [...stats.successfulVideoIds, ...newVideos.map(newVideo => newVideo.youtubeId)];
 			// TODO actually handle failed videos I guess?
 
 			return {
 				...stats,
-				videos: existingVideos.concat(newVideos),
-			}
+				videos: existingVideos.concat(newVideos)
+			};
 		}
 
 		const newVideos = await getVideosFromYoutubeIds(existingYoutubeIds);
@@ -1706,8 +1705,8 @@ class _YouTubeModule extends CoreClass {
 
 		return {
 			...stats,
-			videos: newVideos,
-		}
+			videos: newVideos
+		};
 	}
 
 	/**
@@ -1985,7 +1984,7 @@ class _YouTubeModule extends CoreClass {
 								{
 									url: payload.url,
 									musicOnly: payload.musicOnly,
-									max: payload.max,
+									max: payload.max
 								},
 								this
 							)
@@ -1999,22 +1998,16 @@ class _YouTubeModule extends CoreClass {
 					async youtubeIds => {
 						if (youtubeIds.length === 0) return { videos: [] };
 
-						const {
-							videos,
-							successful,
-							failed,
-							alreadyInDatabase,
-							successfulVideoIds,
-							failedVideoIds,
-						} = await YouTubeModule.runJob(
-							"GET_VIDEOS",
-							{
-								identifiers: youtubeIds,
-								createMissing: true,
-								returnStats: true,
-							},
-							this
-						);
+						const { videos, successful, failed, alreadyInDatabase, successfulVideoIds, failedVideoIds } =
+							await YouTubeModule.runJob(
+								"GET_VIDEOS",
+								{
+									identifiers: youtubeIds,
+									createMissing: true,
+									returnStats: true
+								},
+								this
+							);
 
 						return {
 							videos,
@@ -2022,7 +2015,7 @@ class _YouTubeModule extends CoreClass {
 							failed,
 							alreadyInDatabase,
 							successfulVideoIds,
-							failedVideoIds,
+							failedVideoIds
 						};
 					}
 				],