From 2db8c4cc05efd67fa3e978e986ddb0f1f0e71f42 Mon Sep 17 00:00:00 2001 From: TIANYAO ZHANG <88520881+ZHANGTIANYAO1@users.noreply.github.com> Date: Wed, 18 Nov 2026 18:36:05 +0800 Subject: [PATCH] fix(web): keep FM request timing scoped to its bot and result --- web/src/stores/elapsed.test.ts | 3 ++- web/src/stores/player.ts | 22 +++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/web/src/stores/elapsed.test.ts b/web/src/stores/elapsed.test.ts index 3ea5325..4cd9a0c 100644 --- a/web/src/stores/elapsed.test.ts +++ b/web/src/stores/elapsed.test.ts @@ -59,7 +59,7 @@ describe("playback request timing", () => { vi.unstubAllGlobals(); }); - it.each(["playSong", "playPlaylist", "playAlbum", "playArtist", "next", "playAtIndex"] as const)( + it.each(["playSong", "playPlaylist", "playAlbum", "playArtist", "next", "playAtIndex", "startFm"] as const)( "keeps the current clock when %s fails", async (action) => { const store = usePlayerStore(); @@ -69,6 +69,7 @@ describe("playback request timing", () => { vi.spyOn(axios, "post").mockResolvedValue({ data: { ok: false, message: "播放失败" } }); if (action === "playSong") await store.playSong(track); + else if (action === "startFm") await store.startFm(); else if (action === "next") await store.next(); else if (action === "playAtIndex") await store.playAtIndex(1); else await store[action]("collection"); diff --git a/web/src/stores/player.ts b/web/src/stores/player.ts index db7de1c..9b3f55a 100644 --- a/web/src/stores/player.ts +++ b/web/src/stores/player.ts @@ -428,13 +428,7 @@ export const usePlayerStore = defineStore('player', { }, async fetchQueue() { - if (!this.activeBotId) return; - try { - const res = await axios.get(`/api/player/${this.activeBotId}/queue`); - this.queues[this.activeBotId] = res.data.queue ?? []; - } catch { - // ignore - } + if (this.activeBotId) await this.fetchQueueForBot(this.activeBotId); }, async fetchQueueForBot(botId: string) { @@ -723,14 +717,16 @@ export const usePlayerStore = defineStore('player', { }, async startFm(platform: Source = 'netease') { - if (!this.activeBotId) return; - const res = await axios.post(`/api/player/${this.activeBotId}/fm`, { platform }); - if (res.data?.message) { + const botId = this.activeBotId; + if (!botId) return; + const res = await axios.post(`/api/player/${botId}/fm`, { platform }); + if (this.activeBotId === botId && res.data?.message) { this.notify(res.data.message, res.data.ok === false ? 'error' : 'info'); } - this._setTiming(this.activeBotId, { serverElapsed: 0 }); - this._syncAfterAction(); - this.fetchQueue(); + if (res.data?.ok === true) { + void this.syncElapsed(botId); + void this.fetchQueueForBot(botId); + } }, async fetchFavorites() {