paste songs into playlist

This commit is contained in:
Jason Chen 2022-06-17 13:41:10 -07:00
parent 90dcde279a
commit 7670d0cac1

View file

@ -297,6 +297,13 @@
beforeMount() {
if( window.location.hash.includes("playlist") ) {
window.addEventListener('keydown', this.getCopiedPlayListSongs);
window.addEventListener('keydown', this.pasteSongs);
}
},
beforeDestroy() {
if( window.location.hash.includes("playlist") ) {
window.removeEventListener('keydown', this.getCopiedPlayListSongs);
window.removeEventListener('keydown', this.pasteSongs);
}
},
watch: {
@ -771,6 +778,35 @@
notyf.success(app.getLz('term.share.success'))
}
},
async pasteSongs(event) {
if( event.ctrlKey && event.keyCode === 86 ) {
let clipboard = await navigator.clipboard.readText()
let songs = []
clipboard = clipboard.split(",")
clipboard.forEach(item => {
songs.push({
id: item.substring(item.indexOf("i=")+2, item.length),
type: "songs",
})
})
this.app.mk.api.v3.music(`/v1/me/library/playlists/${this.data.id}/tracks`, {}, {
fetchOptions: {
method: "POST",
body: JSON.stringify({
data: songs
})
}
}).then((response) => {
songs.forEach(item => {
this.app.mk.api.v3.music(`/v1/catalog/${app.mk.storefrontId}/songs/${item.id}`).then((response1) => {
this.displayListing.push(response1.data.data[0])
})
})
})
}
},
search() {
let filtered = [];