Add library sections and track covers
Sections: - The library can be split into named, ordered sections, stored in storage/runtime/sections.json; each track keeps its sectionId. - Sections are created, renamed, reordered and deleted from the page (/api/library/sections). Deleting one keeps its tracks, without a section. - A section, or the tracks without one, can be queued in one go, shuffled or not (enqueue-all takes a sectionId). - The upload form (file or link) picks the section of a kept track. - Without any section, the library stays a plain list. Covers: - A kept track takes the cover embedded in its file (MP3, FLAC...), from the web page or /play garder:. Older tracks are looked at once on startup; a track without one keeps cover: null. - "Renommer" becomes "Modifier": a dialog to change the title, the section and the cover (upload with preview, or removal). - ffmpeg turns covers into JPEGs of at most 512 px, stored in storage/covers and deleted with their track. An uploaded image is only passed to ffmpeg after its signature is checked (PNG, JPEG, WebP, GIF), with that decoder forced, so ffmpeg never guesses the format of an unknown file. - Covers are served under /covers without authentication, since an <img> cannot send the key; their random names are only given by the API and never change content (one-year cache). - The current track and the queue show the cover of their library track. Docs: README lists the new data to back up; storage/covers is ignored. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
3795ee06cb
commit
11ee972636
19 changed files with 1258 additions and 76 deletions
|
|
@ -1,9 +1,12 @@
|
|||
/**
|
||||
* @file Stockage des fichiers audio : storage/temp pour les morceaux joués une seule fois,
|
||||
* storage/permanent et sa liste storage/runtime/library.json pour la bibliothèque.
|
||||
* storage/permanent et sa liste storage/runtime/library.json pour la bibliothèque, et
|
||||
* storage/covers pour les pochettes.
|
||||
*
|
||||
* Contexte : seul module qui crée, déplace ou supprime les fichiers audio et la liste de la
|
||||
* bibliothèque.
|
||||
* bibliothèque. Les pochettes sont créées par libraryCovers.js et les sections rangées par
|
||||
* librarySections.js ; une entrée n'en garde que le nom de fichier (`cover`) et l'identifiant
|
||||
* (`sectionId`).
|
||||
* Points d'entrée : registerUploadedFile (nouveau fichier), getPermanentLibrary,
|
||||
* createQueueTrackFromLibrary, cleanupTemporaryFiles, deleteTrackFile.
|
||||
* Utilisé par : music/ (ajout, file), web/routes/library.js et queue.js, /play, web/server.js.
|
||||
|
|
@ -25,13 +28,14 @@ const STORAGE_ROOT = path.join(process.cwd(), "storage");
|
|||
const PERMANENT_DIR = path.join(STORAGE_ROOT, "permanent");
|
||||
const TEMP_DIR = path.join(STORAGE_ROOT, "temp");
|
||||
const RUNTIME_DIR = path.join(STORAGE_ROOT, "runtime");
|
||||
const COVERS_DIR = path.join(STORAGE_ROOT, "covers");
|
||||
const LIBRARY_FILE = path.join(RUNTIME_DIR, "library.json");
|
||||
const LEGACY_LIBRARY_FILE = path.join(STORAGE_ROOT, "library.json");
|
||||
const TEMP_FILE_MAX_AGE = 24 * 60 * 60 * 1000;
|
||||
const MAX_LIBRARY_SIZE = 2 * 1024 * 1024 * 1024;
|
||||
|
||||
function ensureStorageLayout() {
|
||||
for (const directory of [PERMANENT_DIR, TEMP_DIR, RUNTIME_DIR]) {
|
||||
for (const directory of [PERMANENT_DIR, TEMP_DIR, RUNTIME_DIR, COVERS_DIR]) {
|
||||
fs.mkdirSync(directory, { recursive: true });
|
||||
}
|
||||
|
||||
|
|
@ -100,6 +104,7 @@ function registerUploadedFile(
|
|||
title = file.originalname,
|
||||
duration = null,
|
||||
artist = null,
|
||||
sectionId = null,
|
||||
}
|
||||
) {
|
||||
ensureStorageLayout();
|
||||
|
|
@ -137,6 +142,7 @@ function registerUploadedFile(
|
|||
mimetype: file.mimetype,
|
||||
duration,
|
||||
artist,
|
||||
sectionId,
|
||||
uploader,
|
||||
createdAt,
|
||||
};
|
||||
|
|
@ -236,6 +242,13 @@ function discardUploadedFile(file) {
|
|||
deleteFileSafe(file?.path);
|
||||
}
|
||||
|
||||
// Supprime une pochette d'après son nom de fichier (champ `cover` d'une entrée).
|
||||
function deleteCoverFile(name) {
|
||||
if (typeof name === "string" && name && path.basename(name) === name) {
|
||||
deleteFileSafe(path.join(COVERS_DIR, name));
|
||||
}
|
||||
}
|
||||
|
||||
// Modifie des champs d'entrées de la bibliothèque : updates est une Map id → champs.
|
||||
// Relit le fichier juste avant d'écrire, pour ne pas écraser un ajout fait entre-temps.
|
||||
function updatePermanentTracks(updates) {
|
||||
|
|
@ -264,6 +277,7 @@ function deletePermanentTrack(id) {
|
|||
const [removed] = library.splice(index, 1);
|
||||
writeLibrary(library);
|
||||
deleteFileSafe(removed.path);
|
||||
deleteCoverFile(removed.cover);
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
|
@ -285,7 +299,9 @@ function deleteTrackFile(track) {
|
|||
}
|
||||
|
||||
export {
|
||||
COVERS_DIR,
|
||||
PERMANENT_DIR,
|
||||
RUNTIME_DIR,
|
||||
TEMP_DIR,
|
||||
ensureStorageLayout,
|
||||
registerUploadedFile,
|
||||
|
|
@ -294,6 +310,7 @@ export {
|
|||
createQueueTrackFromLibrary,
|
||||
cleanupTemporaryFiles,
|
||||
discardUploadedFile,
|
||||
deleteCoverFile,
|
||||
deletePermanentTrack,
|
||||
updatePermanentTracks,
|
||||
handleTrackCompletion,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue