mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-01 20:42:50 +08:00
Uploaded local files were deleted whenever a track left the current slot, with no check on whether the file was still needed — causing data loss in several flows. Replace with reference-aware cleanup: a file is deleted only once it has been played AND is no longer referenced by ANY bot's queue (BotManager.getReferencedLocalSongIds wired into the provider via setInUseResolver), with the sweep run AFTER each queue mutation. Fixes: - play-song replay no longer deletes the file it is about to play - loop / repeat-all / prev no longer destroy uploads mid-cycle - a shared upload queued on multiple bots is not deleted while still in use - !play / play-playlist / play-album clean the whole replaced queue, and an empty/failed playlist/album load keeps the previous queue + files intact - bound disk use with an upload quota (evict oldest UNREFERENCED files) - validate uploads by extension against the audio whitelist (never trust the client Content-Type); the stored extension is always a known audio type Deletion now unlinks the file FIRST and drops the record only on success, with a bounded non-blocking retry for briefly-locked files (Windows/ffmpeg), so a failed unlink never orphans a file or diverges index.json. The quota never evicts the just-uploaded file, and long filenames keep their extension. Adds src/music/local.test.ts covering the cleanup lifecycle, quota eviction, and upload validation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>