From 290a9af5e1e03507576a8ea7fbbbac5af510ca1f Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Fri, 30 May 2025 10:35:15 +1000 Subject: [PATCH] fix: update song information in favourites when source URL changes --- public/manifest.json | 2 +- src/components/PlayListItem.vue | 2 +- src/stores/useFavourites.ts | 20 +++++++++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/public/manifest.json b/public/manifest.json index 598bdc4..26d214b 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "MSR Mod", - "version": "0.0.3", + "version": "0.0.4", "description": "塞壬唱片(Monster Siren Records)官网的替代前端。", "content_scripts": [ { diff --git a/src/components/PlayListItem.vue b/src/components/PlayListItem.vue index cf2ba42..c09e80b 100644 --- a/src/components/PlayListItem.vue +++ b/src/components/PlayListItem.vue @@ -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) } }) diff --git a/src/stores/useFavourites.ts b/src/stores/useFavourites.ts index 3439fc7..09f47ee 100644 --- a/src/stores/useFavourites.ts +++ b/src/stores/useFavourites.ts @@ -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 } }) -- 2.45.1