Headers: - Every JavaScript file (sources, front, scripts, tests) starts with a /** @file … */ header, in the three levels used by sokko-g: a short description for simple files; Utilisé par / Attention / @see for shared modules; a full header (context, entry points, callers, dependencies, pitfalls) for index.js, the music queue, the web server, the storage manager and the jukebox page script. - No @author, @version or @since: git already knows. - test/fileHeaders.test.js fails `npm run check` when a header is missing or a central file's header is incomplete. Stylesheet (no visual change, checked by comparing every element's computed styles in Chromium at 1280, 800 and 400 px, hover included): - Role header and section comments. - Transparent shades derive from the colour variables with color-mix() instead of copied rgba() values; new tokens for repeated values (text, text on accent, accent gradient, white veils, shadow). - Native nesting for buttons, the live indicator, upload rows and home cards; drop the unused .hero__visual--large and redundant rules. - Utility classes move to the end so they win over components. The library list's u-mt-1, which never applied (.list reset it), is removed to keep the layout as it was. Docs: CONTRIBUTING.md describes the language, header and stylesheet conventions; CLAUDE.md points to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
/**
|
|
* @file Vérifie l'ajout d'un fichier : titre par défaut, mise en file avec ses métadonnées et
|
|
* suppression d'un fichier qui n'est pas de l'audio.
|
|
*/
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { EventEmitter } from "node:events";
|
|
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-ingest-"));
|
|
process.chdir(temporaryDirectory);
|
|
const storage = await import("../src/web/storage/storageManager.js");
|
|
const { defaultTitle, ingestAudioFile } = await import("../src/music/ingest.js");
|
|
storage.ensureStorageLayout();
|
|
test.after(() => {
|
|
process.chdir(originalDirectory);
|
|
fs.rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
});
|
|
|
|
function fakeQueue() {
|
|
const queue = new EventEmitter();
|
|
queue.enqueued = [];
|
|
queue.enqueue = (track) => queue.enqueued.push(track);
|
|
return queue;
|
|
}
|
|
|
|
function tempFile(name) {
|
|
const filePath = path.join(storage.TEMP_DIR, `upload-${name}`);
|
|
fs.writeFileSync(filePath, "audio");
|
|
return { path: filePath, originalname: name, size: 5, mimetype: "audio/mpeg" };
|
|
}
|
|
|
|
test("default titles come from the tags, else from the file name", () => {
|
|
assert.equal(defaultTitle({ title: "Song", artist: "Band" }, "x.mp3"), "Band - Song");
|
|
assert.equal(defaultTitle({ title: "Song", artist: null }, "x.mp3"), "Song");
|
|
assert.equal(defaultTitle({ title: null, artist: null }, "Mon morceau.flac"), "Mon morceau");
|
|
});
|
|
|
|
test("an ingested file is queued with its metadata", async () => {
|
|
const queue = fakeQueue();
|
|
let libraryUpdates = 0;
|
|
queue.on("libraryUpdate", () => libraryUpdates++);
|
|
|
|
const track = await ingestAudioFile(
|
|
tempFile("a.mp3"),
|
|
{ permanent: true, uploader: "Shinuwa\u0007" },
|
|
{ queue, probe: async () => ({ duration: 61, title: "Titre", artist: "Artiste" }) }
|
|
);
|
|
|
|
assert.equal(track.title, "Artiste - Titre");
|
|
assert.equal(track.duration, 61);
|
|
assert.equal(track.uploader, "Shinuwa");
|
|
assert.deepEqual(queue.enqueued, [track]);
|
|
assert.equal(libraryUpdates, 1);
|
|
assert.equal(storage.getPermanentLibrary()[0].duration, 61);
|
|
});
|
|
|
|
test("a file that is not audio is deleted", async () => {
|
|
const file = tempFile("b.mp3");
|
|
const invalid = Object.assign(new Error("pas de l'audio"), { status: 400 });
|
|
|
|
await assert.rejects(
|
|
ingestAudioFile(file, {}, { queue: fakeQueue(), probe: async () => { throw invalid; } }),
|
|
invalid
|
|
);
|
|
assert.equal(fs.existsSync(file.path), false);
|
|
});
|