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();
});
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");
+9 -13
View File
@@ -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() {