Fix jukebox playback getting stuck and make the web page reflect actions
- Adding a track or someone joining the voice channel now resumes a queue suspended because the bot was alone; before, only the Play button did. - Retry the voice connection with backoff instead of giving up after one failed attempt. - Keep playing when the head of the queue changes while connecting. - Requeue the interrupted track when the bot leaves an empty channel or loses its voice connection. - Removing the current track no longer answers 404; other bots no longer count as listeners. - Accept uploads whatever MIME type the browser sends (ffprobe validates the content) and clean temporary files hourly, sparing queued ones. - Web page: refresh again after an action instead of reusing a stale request, disable buttons while a request runs, show the real start time and custom titles, and support drag and drop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
6ca17264e0
commit
a1cefe6da5
7 changed files with 363 additions and 77 deletions
|
|
@ -8,19 +8,9 @@ import {
|
|||
registerUploadedFile,
|
||||
} from "../storage/storageManager.js";
|
||||
|
||||
const ALLOWED_AUDIO_TYPES = new Set([
|
||||
"audio/aac",
|
||||
"audio/flac",
|
||||
"audio/mp4",
|
||||
"audio/mpeg",
|
||||
"audio/ogg",
|
||||
"audio/wav",
|
||||
"audio/webm",
|
||||
"audio/x-flac",
|
||||
"audio/x-m4a",
|
||||
"audio/x-wav",
|
||||
]);
|
||||
|
||||
// Pas de filtre sur le type MIME : il vient du navigateur et varie selon le système (un MP3
|
||||
// peut arriver en « audio/mp3 », un FLAC sans type). Les fichiers refusés disparaissaient sans
|
||||
// message clair ; ffprobe vérifie le contenu réel après l'envoi.
|
||||
const upload = multer({
|
||||
dest: TEMP_DIR,
|
||||
limits: {
|
||||
|
|
@ -35,7 +25,7 @@ const upload = multer({
|
|||
callback(error);
|
||||
return;
|
||||
}
|
||||
callback(null, ALLOWED_AUDIO_TYPES.has(file.mimetype));
|
||||
callback(null, true);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -101,9 +101,17 @@ function createApp(
|
|||
return app;
|
||||
}
|
||||
|
||||
const TEMP_CLEANUP_INTERVAL = 60 * 60_000;
|
||||
|
||||
function startWebServer(dependencies) {
|
||||
ensureStorageLayout();
|
||||
cleanupTemporaryFiles();
|
||||
const cleanup = () =>
|
||||
cleanupTemporaryFiles(undefined, { keep: dependencies.queue.inUsePaths() });
|
||||
cleanup();
|
||||
// Les fichiers temporaires de plus de 24 h sont supprimés pendant que le bot tourne,
|
||||
// pas seulement à son démarrage.
|
||||
const cleanupInterval = setInterval(cleanup, TEMP_CLEANUP_INTERVAL);
|
||||
cleanupInterval.unref();
|
||||
|
||||
const app = createApp(dependencies);
|
||||
const port = Number(process.env.PORT || config.webServerPort || 3000);
|
||||
|
|
@ -113,6 +121,7 @@ function startWebServer(dependencies) {
|
|||
`[${new Date().toLocaleString()}] Web control server listening on port ${port}`
|
||||
);
|
||||
});
|
||||
server.on("close", () => clearInterval(cleanupInterval));
|
||||
|
||||
return { app, server };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,8 @@ function createQueueTrackFromLibrary(libraryTrack, requestedBy = "library") {
|
|||
};
|
||||
}
|
||||
|
||||
function cleanupTemporaryFiles(maxAge = TEMP_FILE_MAX_AGE) {
|
||||
// keep : chemins encore utilisés (file d'attente, morceau en cours), jamais supprimés.
|
||||
function cleanupTemporaryFiles(maxAge = TEMP_FILE_MAX_AGE, { keep = new Set() } = {}) {
|
||||
ensureStorageLayout();
|
||||
const cutoff = Date.now() - maxAge;
|
||||
|
||||
|
|
@ -181,6 +182,9 @@ function cleanupTemporaryFiles(maxAge = TEMP_FILE_MAX_AGE) {
|
|||
}
|
||||
|
||||
const filePath = path.join(TEMP_DIR, entry.name);
|
||||
if (keep.has(filePath)) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
if (fs.statSync(filePath).mtimeMs < cutoff) {
|
||||
fs.unlinkSync(filePath);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue