fix: update song information in favourites when source URL changes
Some checks failed
Some checks failed
This commit is contained in:
parent
bd74f3fd72
commit
290a9af5e1
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": 3,
|
||||
"name": "MSR Mod",
|
||||
"version": "0.0.3",
|
||||
"version": "0.0.4",
|
||||
"description": "塞壬唱片(Monster Siren Records)官网的替代前端。",
|
||||
"content_scripts": [
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ onMounted(async () => {
|
|||
// 刷新资源地址
|
||||
const updatedSong = await apis.getSong(props.item.song.cid)
|
||||
console.log('Updated song:', updatedSong)
|
||||
props.item.song.sourceUrl = updatedSong.sourceUrl
|
||||
favourites.updateSongInFavourites(props.item.song.cid, updatedSong)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
|
|
@ -282,6 +282,23 @@ export const useFavourites = defineStore('favourites', () => {
|
|||
}
|
||||
}, { deep: true })
|
||||
|
||||
// 更新收藏列表中的歌曲信息
|
||||
const updateSongInFavourites = async (songCid: string, updatedSong: Song) => {
|
||||
const index = favourites.value.findIndex(item => item.song.cid === songCid)
|
||||
if (index !== -1) {
|
||||
// 更新歌曲信息,保持其他属性不变
|
||||
favourites.value[index].song = { ...favourites.value[index].song, ...updatedSong }
|
||||
if (isLoaded.value) {
|
||||
try {
|
||||
await saveFavourites()
|
||||
} catch (error) {
|
||||
// 保存失败时可以考虑回滚或错误处理
|
||||
console.error('Failed to save updated song:', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 立即初始化
|
||||
initializeFavourites()
|
||||
|
||||
|
@ -299,7 +316,8 @@ export const useFavourites = defineStore('favourites', () => {
|
|||
toggleFavourite,
|
||||
clearFavourites,
|
||||
getStoredValue,
|
||||
setStoredValue
|
||||
setStoredValue,
|
||||
updateSongInFavourites
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user