fix(web): keep FM request timing scoped to its bot and result

This commit is contained in:
TIANYAO ZHANG committed 2026-11-18 18:36:05 +08:00
1 parent f965b70c22
commit 2db8c4cc05
2 files changed
+11 -14

No files matched your search

+2 -1
View File
@@ -59,7 +59,7 @@ describe("playback request timing", () => {
vi.unstubAllGlobals(); 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", "keeps the current clock when %s fails",
async (action) => { async (action) => {
const store = usePlayerStore(); const store = usePlayerStore();
@@ -69,6 +69,7 @@ describe("playback request timing", () => {
vi.spyOn(axios, "post").mockResolvedValue({ data: { ok: false, message: "播放失败" } }); vi.spyOn(axios, "post").mockResolvedValue({ data: { ok: false, message: "播放失败" } });
if (action === "playSong") await store.playSong(track); if (action === "playSong") await store.playSong(track);
else if (action === "startFm") await store.startFm();
else if (action === "next") await store.next(); else if (action === "next") await store.next();
else if (action === "playAtIndex") await store.playAtIndex(1); else if (action === "playAtIndex") await store.playAtIndex(1);
else await store[action]("collection"); else await store[action]("collection");
+9 -13
View File
@@ -428,13 +428,7 @@ export const usePlayerStore = defineStore('player', {
}, },
async fetchQueue() { async fetchQueue() {
if (!this.activeBotId) return; if (this.activeBotId) await this.fetchQueueForBot(this.activeBotId);
try {
const res = await axios.get(`/api/player/${this.activeBotId}/queue`);
this.queues[this.activeBotId] = res.data.queue ?? [];
} catch {
// ignore
}
}, },
async fetchQueueForBot(botId: string) { async fetchQueueForBot(botId: string) {
@@ -723,14 +717,16 @@ export const usePlayerStore = defineStore('player', {
}, },
async startFm(platform: Source = 'netease') { async startFm(platform: Source = 'netease') {
if (!this.activeBotId) return; const botId = this.activeBotId;
const res = await axios.post(`/api/player/${this.activeBotId}/fm`, { platform }); if (!botId) return;
if (res.data?.message) { 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.notify(res.data.message, res.data.ok === false ? 'error' : 'info');
} }
this._setTiming(this.activeBotId, { serverElapsed: 0 }); if (res.data?.ok === true) {
this._syncAfterAction(); void this.syncElapsed(botId);
this.fetchQueue(); void this.fetchQueueForBot(botId);
}
}, },
async fetchFavorites() { async fetchFavorites() {