mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-12-03 03:12:51 +08:00
fix(web): preserve playback on invalid queue selections
This commit is contained in:
1 parent
afb1cd7c14
commit
5c2a9468bd
4 files changed
+64
-19
No files matched your search
@@ -59,7 +59,7 @@ describe("playback request timing", () => {
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
it.each(["playSong", "playPlaylist", "playAlbum", "playArtist", "next"] as const)(
|
||||
it.each(["playSong", "playPlaylist", "playAlbum", "playArtist", "next", "playAtIndex"] as const)(
|
||||
"keeps the current clock when %s fails",
|
||||
async (action) => {
|
||||
const store = usePlayerStore();
|
||||
@@ -70,6 +70,7 @@ describe("playback request timing", () => {
|
||||
|
||||
if (action === "playSong") await store.playSong(track);
|
||||
else if (action === "next") await store.next();
|
||||
else if (action === "playAtIndex") await store.playAtIndex(1);
|
||||
else await store[action]("collection");
|
||||
|
||||
expect(store.timings.a).toEqual(current);
|
||||
|
||||
@@ -402,7 +402,8 @@ export const usePlayerStore = defineStore('player', {
|
||||
},
|
||||
|
||||
/** Poll the same bot for authoritative elapsed time. */
|
||||
async syncElapsed(botId = this.activeBotId) {
|
||||
async syncElapsed(botId?: string) {
|
||||
botId ??= this.activeBotId ?? undefined;
|
||||
if (!botId || !this.bots.some(bot => bot.id === botId && bot.playing && !bot.paused)) return;
|
||||
const timing = this.timings[botId];
|
||||
try {
|
||||
@@ -449,10 +450,11 @@ export const usePlayerStore = defineStore('player', {
|
||||
},
|
||||
|
||||
async playAtIndex(index: number) {
|
||||
if (!this.activeBotId) return;
|
||||
await axios.post(`/api/player/${this.activeBotId}/play-at`, { index });
|
||||
this._setTiming(this.activeBotId, { serverElapsed: 0 });
|
||||
this._syncAfterAction();
|
||||
const botId = this.activeBotId;
|
||||
if (!botId) return;
|
||||
const res = await axios.post(`/api/player/${botId}/play-at`, { index });
|
||||
if (res.data?.ok === false && res.data?.message) this.notify(res.data.message, 'error');
|
||||
if (res.data?.ok === true) void this.syncElapsed(botId);
|
||||
},
|
||||
|
||||
async play(query: string, platform = 'netease') {
|
||||
|
||||
Reference in new issue
Block a user