fix: update song information in favourites when source URL changes
Some checks failed
构建扩展程序 / 构建 Chrome 扩展程序 (push) Successful in 1m6s
构建扩展程序 / 构建 Firefox 附加组件 (push) Has been cancelled
构建扩展程序 / 发布至 Chrome 应用商店 (push) Has been cancelled
构建扩展程序 / 发布至 Firefox 附加组件库 (push) Has been cancelled
构建扩展程序 / 发布至 Edge 附加组件商店 (push) Has been cancelled

This commit is contained in:
Astrian Zheng 2025-05-30 10:35:15 +10:00
parent bd74f3fd72
commit 290a9af5e1
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA
3 changed files with 21 additions and 3 deletions

View File

@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "MSR Mod",
"version": "0.0.3",
"version": "0.0.4",
"description": "塞壬唱片Monster Siren Records官网的替代前端。",
"content_scripts": [
{

View File

@ -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>

View File

@ -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
}
})