mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat: play-by-id and play-playlist endpoints, fix lyrics sync timing
- New endpoints: play-by-id, add-by-id, play-playlist (load all songs at once) - Playlist 'Play All' now uses server-side bulk load (no N sequential searches) - Search/Home/Playlist views use playById instead of search-by-name - Fixed updateBotStatus timing: capture prev state before mutation - Early return on song change prevents stale pause/resume logic Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2c87f1cff9
commit
2e4d6d8d40
6 files changed
+163
-20
No files matched your search
@@ -76,10 +76,14 @@ export const usePlayerStore = defineStore('player', {
|
||||
},
|
||||
|
||||
updateBotStatus(botId: string, status: BotStatus) {
|
||||
// Capture previous state BEFORE updating
|
||||
const prev = this.bots.find((b) => b.id === botId);
|
||||
const prevSongId = prev?.currentSong?.id;
|
||||
const prevPaused = prev?.paused ?? false;
|
||||
const prevPlaying = prev?.playing ?? false;
|
||||
const newSongId = status.currentSong?.id;
|
||||
|
||||
// Update the bot status
|
||||
const index = this.bots.findIndex((b) => b.id === botId);
|
||||
if (index >= 0) {
|
||||
this.bots[index] = status;
|
||||
@@ -87,19 +91,24 @@ export const usePlayerStore = defineStore('player', {
|
||||
this.bots.push(status);
|
||||
}
|
||||
|
||||
// Reset play timer when song changes
|
||||
// Only adjust timing for the active bot
|
||||
if (botId !== (this.activeBotId ?? this.bots[0]?.id)) return;
|
||||
|
||||
// Song changed — reset timer
|
||||
if (newSongId && newSongId !== prevSongId) {
|
||||
this.playStartedAt = Date.now();
|
||||
this.pausedElapsed = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Track pause/resume
|
||||
if (status.playing && !status.paused && prev?.paused) {
|
||||
// Resumed — adjust start time
|
||||
// Resumed from pause
|
||||
if (status.playing && !status.paused && prevPaused) {
|
||||
this.playStartedAt = Date.now() - this.pausedElapsed * 1000;
|
||||
return;
|
||||
}
|
||||
if (status.paused && !prev?.paused) {
|
||||
// Paused — save elapsed
|
||||
|
||||
// Paused
|
||||
if (status.paused && prevPlaying && !prevPaused) {
|
||||
this.pausedElapsed = this.playStartedAt > 0
|
||||
? (Date.now() - this.playStartedAt) / 1000
|
||||
: 0;
|
||||
@@ -154,11 +163,30 @@ export const usePlayerStore = defineStore('player', {
|
||||
this.pausedElapsed = 0;
|
||||
},
|
||||
|
||||
async playById(songId: string, platform = 'netease') {
|
||||
if (!this.activeBotId) return;
|
||||
await axios.post(`/api/player/${this.activeBotId}/play-by-id`, { songId, platform });
|
||||
this.playStartedAt = Date.now();
|
||||
this.pausedElapsed = 0;
|
||||
},
|
||||
|
||||
async addToQueue(query: string, platform = 'netease') {
|
||||
if (!this.activeBotId) return;
|
||||
await axios.post(`/api/player/${this.activeBotId}/add`, { query, platform });
|
||||
},
|
||||
|
||||
async addToQueueById(songId: string, platform = 'netease') {
|
||||
if (!this.activeBotId) return;
|
||||
await axios.post(`/api/player/${this.activeBotId}/add-by-id`, { songId, platform });
|
||||
},
|
||||
|
||||
async playPlaylist(playlistId: string, platform = 'netease') {
|
||||
if (!this.activeBotId) return;
|
||||
await axios.post(`/api/player/${this.activeBotId}/play-playlist`, { playlistId, platform });
|
||||
this.playStartedAt = Date.now();
|
||||
this.pausedElapsed = 0;
|
||||
},
|
||||
|
||||
async pause() {
|
||||
if (!this.activeBotId) return;
|
||||
this.pausedElapsed = this.playStartedAt > 0
|
||||
|
||||
Reference in new issue
Block a user