Add library sections and track covers
All checks were successful
Deploy Palico Bot / check (push) Successful in 9s
Deploy Palico Bot / deploy (push) Successful in 7s

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:
Shinuwa 2026-12-01 21:27:49 +01:00
parent 3795ee06cb
commit 11ee972636
19 changed files with 1258 additions and 76 deletions

View file

@ -0,0 +1,68 @@
/**
* @file Vérifie les sections de la bibliothèque : création, renommage, déplacement, et suppression qui
* remet ses morceaux sans section.
*/
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
// storageManager.js fixe ses dossiers au chargement, d'après le répertoire de travail.
const originalDirectory = process.cwd();
const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "palico-sections-"));
process.chdir(temporaryDirectory);
const storage = await import("../src/web/storage/storageManager.js");
const sections = await import("../src/web/storage/librarySections.js");
storage.ensureStorageLayout();
test.after(() => {
process.chdir(originalDirectory);
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
});
function addTrack(name, sectionId) {
const filePath = path.join(storage.TEMP_DIR, `upload-${name}`);
fs.writeFileSync(filePath, "audio");
return storage.registerUploadedFile(
{ path: filePath, originalname: name, size: 5, mimetype: "audio/mpeg" },
{ permanent: true, uploader: "test", sectionId }
).libraryTrackId;
}
test("sections are created, renamed and reordered", () => {
assert.deepEqual(sections.getSections(), []);
const chill = sections.createSection(" Chill\u0007 ");
const boss = sections.createSection("Combats de boss");
const menu = sections.createSection("Menus");
assert.equal(chill.name, "Chill");
sections.updateSection(menu.id, { name: "Écrans titres", position: 0 });
assert.deepEqual(
sections.getSections().map((section) => section.name),
["Écrans titres", "Chill", "Combats de boss"]
);
assert.equal(sections.findSection(boss.id).name, "Combats de boss");
assert.equal(sections.updateSection("unknown", { name: "x" }), null);
});
test("invalid names and positions are refused", () => {
const [first] = sections.getSections();
assert.throws(() => sections.createSection(" "), { status: 400 });
assert.throws(() => sections.updateSection(first.id, { position: 99 }), { status: 400 });
assert.throws(() => sections.updateSection(first.id, { position: "1" }), { status: 400 });
});
test("deleting a section keeps its tracks, without a section", () => {
const doomed = sections.createSection("À supprimer");
const kept = sections.createSection("Gardée");
const inDoomed = addTrack("a.mp3", doomed.id);
const inKept = addTrack("b.mp3", kept.id);
assert.equal(sections.deleteSection(doomed.id).id, doomed.id);
assert.equal(sections.findSection(doomed.id), undefined);
assert.equal(storage.findPermanentTrack(inDoomed).sectionId, null);
assert.equal(storage.findPermanentTrack(inKept).sectionId, kept.id);
assert.equal(sections.deleteSection(doomed.id), null);
});