소스 검색

fix: many backend eslint errors

Kristian Vos 1 년 전
부모
커밋
c72ab80b64

+ 0 - 1
backend/logic/actions/apis.js

@@ -12,7 +12,6 @@ const UtilsModule = moduleManager.modules.utils;
 const WSModule = moduleManager.modules.ws;
 const YouTubeModule = moduleManager.modules.youtube;
 const SpotifyModule = moduleManager.modules.spotify;
-const CacheModule = moduleManager.modules.cache;
 
 export default {
 	/**

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

@@ -1436,13 +1436,13 @@ export default {
 						this
 					)
 						.then(res => {
-							const { playlist, song, ratings } = res;
-							next(null, playlist, song, ratings);
+							const { playlist, song } = res;
+							next(null, playlist, song);
 						})
 						.catch(next);
 				}
 			],
-			async (err, playlist, newSong, ratings) => {
+			async (err, playlist, newSong) => {
 				if (err) {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(

+ 0 - 2
backend/logic/actions/soundcloud.js

@@ -1,7 +1,5 @@
-import mongoose from "mongoose";
 import async from "async";
 
-import isLoginRequired from "../hooks/loginRequired";
 import { useHasPermission } from "../hooks/hasPermission";
 
 // eslint-disable-next-line

+ 0 - 6
backend/logic/actions/spotify.js

@@ -1,15 +1,9 @@
-import mongoose from "mongoose";
-import async from "async";
-
-import isLoginRequired from "../hooks/loginRequired";
 import { useHasPermission } from "../hooks/hasPermission";
 
 // eslint-disable-next-line
 import moduleManager from "../../index";
 
-const DBModule = moduleManager.modules.db;
 const UtilsModule = moduleManager.modules.utils;
-const SoundcloudModule = moduleManager.modules.soundcloud;
 const SpotifyModule = moduleManager.modules.spotify;
 
 export default {

+ 0 - 14
backend/logic/musicbrainz.js

@@ -1,5 +1,3 @@
-import config from "config";
-
 import axios from "axios";
 
 import CoreClass from "../core";
@@ -36,13 +34,7 @@ class RateLimitter {
 }
 
 let MusicBrainzModule;
-let CacheModule;
 let DBModule;
-let MediaModule;
-let SongsModule;
-let StationsModule;
-let PlaylistsModule;
-let WSModule;
 
 class _MusicBrainzModule extends CoreClass {
 	// eslint-disable-next-line require-jsdoc
@@ -63,13 +55,7 @@ class _MusicBrainzModule extends CoreClass {
 	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async initialize() {
-		CacheModule = this.moduleManager.modules.cache;
 		DBModule = this.moduleManager.modules.db;
-		MediaModule = this.moduleManager.modules.media;
-		SongsModule = this.moduleManager.modules.songs;
-		StationsModule = this.moduleManager.modules.stations;
-		PlaylistsModule = this.moduleManager.modules.playlists;
-		WSModule = this.moduleManager.modules.ws;
 
 		this.genericApiRequestModel = this.GenericApiRequestModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "genericApiRequest"

+ 1 - 1
backend/logic/playlists.js

@@ -610,7 +610,7 @@ class _PlaylistsModule extends CoreClass {
 							MediaModule.runJob("RECALCULATE_RATINGS", {
 								mediaSource: oldMediaSource
 							})
-								.then(ratings => next(null, playlist, newSong, newRatings, oldRatings))
+								.then(oldRatings => next(null, playlist, newSong, newRatings, oldRatings))
 								.catch(next);
 						} else {
 							next(null, playlist, newSong, null, null);

+ 26 - 11
backend/logic/soundcloud.js

@@ -155,8 +155,9 @@ class _SoundCloudModule extends CoreClass {
 	}
 
 	/**
+	 * Generates/fetches a new SoundCloud API key
 	 *
-	 * @returns
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	GENERATE_SOUNDCLOUD_API_KEY() {
 		return new Promise((resolve, reject) => {
@@ -197,8 +198,9 @@ class _SoundCloudModule extends CoreClass {
 	}
 
 	/**
+	 * Tests the stored SoundCloud API key
 	 *
-	 * @returns
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	TEST_SOUNDCLOUD_API_KEY() {
 		return new Promise((resolve, reject) => {
@@ -206,7 +208,8 @@ class _SoundCloudModule extends CoreClass {
 			CacheModule.runJob("GET", { key: "soundcloudApiKey" }, this).then(soundcloudApiKey => {
 				if (!soundcloudApiKey) {
 					this.log("ERROR", "No SoundCloud API key found in cache.");
-					return resolve(false);
+					resolve(false);
+					return;
 				}
 
 				SoundCloudModule.soundcloudApiKey = soundcloudApiKey;
@@ -392,10 +395,11 @@ class _SoundCloudModule extends CoreClass {
 	}
 
 	/**
-	 * Gets a track from a SoundCloud URL
+	 * Tries to get a SoundCloud track from a URL
 	 *
-	 * @param {*} payload
-	 * @returns {Promise}
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.identifier - the SoundCloud track URL
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	GET_TRACK_FROM_URL(payload) {
 		return new Promise((resolve, reject) => {
@@ -407,7 +411,10 @@ class _SoundCloudModule extends CoreClass {
 					next => {
 						const match = scRegex.exec(payload.identifier);
 
-						if (!match || !match.groups) return next("Invalid SoundCloud URL.");
+						if (!match || !match.groups) {
+							next("Invalid SoundCloud URL.");
+							return;
+						}
 
 						const { userPermalink, permalink } = match.groups;
 
@@ -415,15 +422,23 @@ class _SoundCloudModule extends CoreClass {
 					},
 
 					(_dbTrack, next) => {
-						if (_dbTrack) return next(null, _dbTrack, true);
+						if (_dbTrack) {
+							next(null, _dbTrack, true);
+							return;
+						}
 
 						SoundCloudModule.runJob("API_RESOLVE", { url: payload.identifier }, this)
 							.then(({ response }) => {
 								const { data } = response;
-								if (!data || !data.id)
-									return next("The provided URL does not exist or cannot be accessed.");
+								if (!data || !data.id) {
+									next("The provided URL does not exist or cannot be accessed.");
+									return;
+								}
 
-								if (data.kind !== "track") return next(`Invalid URL provided. Kind got: ${data.kind}.`);
+								if (data.kind !== "track") {
+									next(`Invalid URL provided. Kind got: ${data.kind}.`);
+									return;
+								}
 
 								// TODO get more data here
 

+ 56 - 31
backend/logic/spotify.js

@@ -18,7 +18,6 @@ let WikiDataModule;
 
 const youtubeVideoUrlRegex =
 	/^(https?:\/\/)?(www\.)?(m\.)?(music\.)?(youtube\.com|youtu\.be)\/(watch\?v=)?(?<youtubeId>[\w-]{11})((&([A-Za-z0-9]+)?)*)?$/;
-const youtubeVideoIdRegex = /^([\w-]{11})$/;
 
 const spotifyTrackObjectToMusareTrackObject = spotifyTrackObject => ({
 	trackId: spotifyTrackObject.id,
@@ -123,8 +122,9 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Fetches a Spotify API token from either the cache, or Spotify using the client id and secret from the config
 	 *
-	 * @returns
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	GET_API_TOKEN() {
 		return new Promise((resolve, reject) => {
@@ -366,7 +366,10 @@ class _SpotifyModule extends CoreClass {
 							const trackIds = spotifyTracks.map(spotifyTrack => spotifyTrack.trackId);
 
 							SpotifyModule.spotifyTrackModel.find({ trackId: trackIds }, (err, existingTracks) => {
-								if (err) return next(err);
+								if (err) {
+									next(err);
+									return;
+								}
 
 								const existingTrackIds = existingTracks.map(existingTrack => existingTrack.trackId);
 
@@ -467,8 +470,9 @@ class _SpotifyModule extends CoreClass {
 	/**
 	 * Gets tracks from media sources
 	 *
-	 * @param {object} payload
-	 * @returns {Promise}
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.mediaSources - the media sources to get tracks from
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_TRACKS_FROM_MEDIA_SOURCES(payload) {
 		return new Promise((resolve, reject) => {
@@ -511,10 +515,11 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
-	 * Gets albums from ids
+	 * Gets albums from Spotify album ids
 	 *
-	 * @param {object} payload
-	 * @returns {Promise}
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.albumIds - the Spotify album ids
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALBUMS_FROM_IDS(payload) {
 		const { albumIds } = payload;
@@ -563,10 +568,11 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
-	 * Gets artists from ids
+	 * Gets Spotify artists from Spotify artist ids
 	 *
-	 * @param {object} payload
-	 * @returns {Promise}
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.artistIds - the Spotify artist ids
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ARTISTS_FROM_IDS(payload) {
 		const { artistIds } = payload;
@@ -733,8 +739,10 @@ class _SpotifyModule extends CoreClass {
 										.then(({ response }) => {
 											const { data } = response;
 
-											if (!data)
-												return next("The provided URL does not exist or cannot be accessed.");
+											if (!data) {
+												next("The provided URL does not exist or cannot be accessed.");
+												return;
+											}
 
 											total = data.total;
 											nextUrl = data.next;
@@ -753,8 +761,8 @@ class _SpotifyModule extends CoreClass {
 							},
 							err => {
 								if (err) next(err);
-								else {
-									return SpotifyModule.runJob("CREATE_TRACKS", { spotifyTracks }, this)
+								else
+									SpotifyModule.runJob("CREATE_TRACKS", { spotifyTracks }, this)
 										.then(() => {
 											next(
 												null,
@@ -762,7 +770,6 @@ class _SpotifyModule extends CoreClass {
 											);
 										})
 										.catch(next);
-								}
 							}
 						);
 					}
@@ -787,9 +794,12 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Tries to get alternative artists sources for a list of Spotify artist ids
 	 *
-	 * @param {*} payload
-	 * @returns
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.artistIds - the Spotify artist ids to try and get alternative artist sources for
+	 * @param {string} payload.collectAlternativeArtistSourcesOrigins - whether to collect the origin of any alternative artist sources found
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALTERNATIVE_ARTIST_SOURCES_FOR_ARTISTS(payload) {
 		const { artistIds, collectAlternativeArtistSourcesOrigins } = payload;
@@ -832,12 +842,15 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Tries to get alternative artist sources for a Spotify artist id
 	 *
-	 * @param {*} payload
-	 * @returns
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.artistId - the Spotify artist id to try and get alternative artist sources for
+	 * @param {string} payload.collectAlternativeArtistSourcesOrigins - whether to collect the origin of any alternative artist sources found
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALTERNATIVE_ARTIST_SOURCES_FOR_ARTIST(payload) {
-		const { artistId, collectAlternativeArtistSourcesOrigins } = payload;
+		const { artistId /* , collectAlternativeArtistSourcesOrigins */ } = payload;
 
 		if (!artistId) throw new Error("Artist id provided is not valid.");
 
@@ -887,9 +900,12 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Tries to get alternative album sources for a list of Spotify album ids
 	 *
-	 * @param {*} payload
-	 * @returns
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.albumIds - the Spotify album ids to try and get alternative album sources for
+	 * @param {string} payload.collectAlternativeAlbumSourcesOrigins - whether to collect the origin of any alternative album sources found
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALTERNATIVE_ALBUM_SOURCES_FOR_ALBUMS(payload) {
 		const { albumIds, collectAlternativeAlbumSourcesOrigins } = payload;
@@ -932,12 +948,15 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Tries to get alternative album sources for a Spotify album id
 	 *
-	 * @param {*} payload
-	 * @returns
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.albumId - the Spotify album id to try and get alternative album sources for
+	 * @param {string} payload.collectAlternativeAlbumSourcesOrigins - whether to collect the origin of any alternative album sources found
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALTERNATIVE_ALBUM_SOURCES_FOR_ALBUM(payload) {
-		const { albumId, collectAlternativeAlbumSourcesOrigins } = payload;
+		const { albumId /* , collectAlternativeAlbumSourcesOrigins */ } = payload;
 
 		if (!albumId) throw new Error("Album id provided is not valid.");
 
@@ -967,9 +986,12 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Tries to get alternative track sources for a list of Spotify track media sources
 	 *
-	 * @param {*} payload
-	 * @returns
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.mediaSources - the Spotify media sources to try and get alternative track sources for
+	 * @param {string} payload.collectAlternativeMediaSourcesOrigins - whether to collect the origin of any alternative track sources found
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALTERNATIVE_MEDIA_SOURCES_FOR_TRACKS(payload) {
 		const { mediaSources, collectAlternativeMediaSourcesOrigins } = payload;
@@ -1016,9 +1038,12 @@ class _SpotifyModule extends CoreClass {
 	}
 
 	/**
+	 * Tries to get alternative track sources for a Spotify track media source
 	 *
-	 * @param {*} payload
-	 * @returns
+	 * @param {object} payload - object that contains the payload
+	 * @param {string} payload.mediaSource - the Spotify media source to try and get alternative track sources for
+	 * @param {string} payload.collectAlternativeMediaSourcesOrigins - whether to collect the origin of any alternative track sources found
+	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async GET_ALTERNATIVE_MEDIA_SOURCES_FOR_TRACK(payload) {
 		const { mediaSource, collectAlternativeMediaSourcesOrigins } = payload;
@@ -1339,7 +1364,7 @@ class _SpotifyModule extends CoreClass {
 			const releaseGroupIds = new Set();
 
 			RecordingApiResponse.recordings.forEach(recording => {
-				const recordingId = recording.id;
+				// const recordingId = recording.id;
 				// console.log("Recording:", recording.id);
 
 				recording.releases.forEach(release => {

+ 7 - 9
backend/logic/stations.js

@@ -127,13 +127,6 @@ class _StationsModule extends CoreClass {
 		const stationModel = (this.stationModel = await DBModule.runJob("GET_MODEL", { modelName: "station" }));
 		const stationSchema = (this.stationSchema = await CacheModule.runJob("GET_SCHEMA", { schemaName: "station" }));
 
-		const stationHistoryModel = (this.stationHistoryModel = await DBModule.runJob("GET_MODEL", {
-			modelName: "stationHistory"
-		}));
-		const stationHistorySchema = (this.stationHistorySchema = await CacheModule.runJob("GET_SCHEMA", {
-			schemaName: "stationHistory"
-		}));
-
 		return new Promise((resolve, reject) => {
 			async.waterfall(
 				[
@@ -980,9 +973,14 @@ class _StationsModule extends CoreClass {
 	}
 
 	/**
+	 * Creates a station history item
 	 *
-	 *
-	 * @param {*} payload
+	 * @param {object} payload - object containing the payload
+	 * @param {string} payload.stationId - the station id to create the history item for
+	 * @param {string} payload.currentSong - the song to create the history item for
+	 * @param {string} payload.skipReason - the reason the song was skipped
+	 * @param {string} payload.skippedAt - the date/time the song was skipped
+	 * @returns {Promise} - returns a promise (resolve, reject)
 	 */
 	async ADD_STATION_HISTORY_ITEM(payload) {
 		if (!config.get("experimental.station_history")) throw new Error("Station history is not enabled");

+ 0 - 14
backend/logic/wikidata.js

@@ -1,5 +1,3 @@
-import config from "config";
-
 import axios from "axios";
 
 import CoreClass from "../core";
@@ -36,13 +34,7 @@ class RateLimitter {
 }
 
 let WikiDataModule;
-let CacheModule;
 let DBModule;
-let MediaModule;
-let SongsModule;
-let StationsModule;
-let PlaylistsModule;
-let WSModule;
 
 class _WikiDataModule extends CoreClass {
 	// eslint-disable-next-line require-jsdoc
@@ -63,13 +55,7 @@ class _WikiDataModule extends CoreClass {
 	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
 	async initialize() {
-		CacheModule = this.moduleManager.modules.cache;
 		DBModule = this.moduleManager.modules.db;
-		MediaModule = this.moduleManager.modules.media;
-		SongsModule = this.moduleManager.modules.songs;
-		StationsModule = this.moduleManager.modules.stations;
-		PlaylistsModule = this.moduleManager.modules.playlists;
-		WSModule = this.moduleManager.modules.ws;
 
 		this.genericApiRequestModel = this.GenericApiRequestModel = await DBModule.runJob("GET_MODEL", {
 			modelName: "genericApiRequest"