Browse Source

feat: added more SoundCloud support

Kristian Vos 2 years ago
parent
commit
12ae457fab

+ 41 - 3
backend/logic/actions/soundcloud.js

@@ -8,12 +8,50 @@ import { useHasPermission } from "../hooks/hasPermission";
 import moduleManager from "../../index";
 
 const DBModule = moduleManager.modules.db;
-const CacheModule = moduleManager.modules.cache;
 const UtilsModule = moduleManager.modules.utils;
-const YouTubeModule = moduleManager.modules.youtube;
-const MediaModule = moduleManager.modules.media;
+const SoundcloudModule = moduleManager.modules.soundcloud;
 
 export default {
+	/**
+	 * Fetches new SoundCloud API key
+	 *
+	 * @returns {{status: string, data: object}}
+	 */
+	fetchNewApiKey: useHasPermission("admin.view.soundcloud", function fetchNewApiKey(session, cb) {
+		SoundcloudModule.runJob("GENERATE_SOUNDCLOUD_API_KEY", {}, this)
+			.then(response => {
+				this.log("SUCCESS", "SOUNDCLOUD_FETCH_NEW_API_KEY", `Fetching new API key was successful.`);
+				return cb({ status: "success", data: { status: response.status } });
+			})
+			.catch(async err => {
+				err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+				this.log("ERROR", "SOUNDCLOUD_FETCH_NEW_API_KEY", `Fetching new API key failed. "${err}"`);
+				return cb({ status: "error", message: err });
+			});
+	}),
+
+	/**
+	 * Tests SoundCloud API key
+	 *
+	 * @returns {{status: string, data: object}}
+	 */
+	testApiKey: useHasPermission("admin.view.soundcloud", function testApiKey(session, cb) {
+		SoundcloudModule.runJob("TEST_SOUNDCLOUD_API_KEY", {}, this)
+			.then(response => {
+				this.log(
+					"SUCCESS",
+					"SOUNDCLOUD_TEST_API_KEY",
+					`Testing API key was successful. Response: ${response}.`
+				);
+				return cb({ status: "success", data: { status: response.status } });
+			})
+			.catch(async err => {
+				err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
+				this.log("ERROR", "SOUNDCLOUD_TEST_API_KEY", `Testing API key failed. "${err}"`);
+				return cb({ status: "error", message: err });
+			});
+	}),
+
 	// /**
 	//  * Returns details about the YouTube quota usage
 	//  *

+ 10 - 3
backend/logic/soundcloud.js

@@ -197,6 +197,8 @@ class _SoundCloudModule extends CoreClass {
 					return resolve(false);
 				}
 
+				SoundCloudModule.soundcloudApiKey = soundcloudApiKey;
+
 				sckey
 					.testKey(soundcloudApiKey)
 					.then(res => {
@@ -460,7 +462,7 @@ class _SoundCloudModule extends CoreClass {
 								if (!data || !data.id)
 									return next("The provided URL does not exist or cannot be accessed.");
 
-								if (data.kind !== "playlist")
+								if (data.kind !== "playlist" && data.kind !== "system-playlist")
 									return next(`Invalid URL provided. Kind got: ${data.kind}.`);
 
 								const { tracks } = data;
@@ -476,8 +478,13 @@ class _SoundCloudModule extends CoreClass {
 				],
 				(err, soundcloudTrackIds) => {
 					if (err && err !== true) {
-						SoundCloudModule.log("ERROR", "GET_PLAYLIST", "Some error has occurred.", err.message);
-						reject(new Error(err.message));
+						SoundCloudModule.log(
+							"ERROR",
+							"GET_PLAYLIST",
+							"Some error has occurred.",
+							typeof err === "string" ? err : err.message
+						);
+						reject(new Error(typeof err === "string" ? err : err.message));
 					} else {
 						resolve({ songs: soundcloudTrackIds });
 					}

+ 19 - 2
frontend/src/pages/Admin/SoundCloud/index.vue

@@ -1,4 +1,21 @@
-<script setup lang="ts"></script>
+<script setup lang="ts">
+import { defineAsyncComponent, ref } from "vue";
+
+const RunJobDropdown = defineAsyncComponent(
+	() => import("@/components/RunJobDropdown.vue")
+);
+
+const jobs = ref([
+	{
+		name: "Fetch new SoundCloud API key",
+		socket: "soundcloud.fetchNewApiKey"
+	},
+	{
+		name: "Test SoundCloud API key",
+		socket: "soundcloud.testApiKey"
+	}
+]);
+</script>
 
 <template>
 	<div class="admin-tab container">
@@ -8,7 +25,7 @@
 				<h1>SoundCloud API</h1>
 			</div>
 			<div class="button-row">
-				<!-- <run-job-dropdown :jobs="jobs" /> -->
+				<run-job-dropdown :jobs="jobs" />
 			</div>
 		</div>
 	</div>