From 74e1e3d38aa2304eaf770d64ff4f26e6fcc3c8a3 Mon Sep 17 00:00:00 2001 From: vapormusic Date: Thu, 8 Sep 2022 18:16:00 +0700 Subject: [PATCH] fix add to lib for suggestion contextmenu --- src/renderer/views/components/smarthints.ejs | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/renderer/views/components/smarthints.ejs b/src/renderer/views/components/smarthints.ejs index 7abecd87..c841d222 100644 --- a/src/renderer/views/components/smarthints.ejs +++ b/src/renderer/views/components/smarthints.ejs @@ -50,6 +50,28 @@ async mounted() { }, methods: { + async isInLibrary() { + if (this.item.type && !this.item.type.includes("library")) { + let params = { + relate: "library", + "fields": "inLibrary", + "extend": this.revisedRandId() + } + let kind = this.item.type ?? this.item.attributes.playParams.kind + let truekind = (!kind.endsWith("s")) ? (kind + "s") : kind; + if (truekind === "musicVideos") { + truekind = "music-videos" + } + let res = await app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/?ids[${truekind}]=${this.item.attributes.playParams.id ?? this.item.id}`, params); + res = res.data.data[0] + this.addedToLibrary = (res && res.attributes && res.attributes.inLibrary) ? res.attributes.inLibrary : false + } else { + this.addedToLibrary = true + } + }, + revisedRandId() { + return Math.random().toString(36).replace(/[^a-z]+/g, '').slice(2, 10); + }, uuidv4() { return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) @@ -276,7 +298,7 @@ }) } catch (e) { - + console.log(e) } try { let rating = await app.getRating(self.item)