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,6 +1,6 @@
|
|||
/**
|
||||
* @file Page du jukebox : connexion (Discord ou mot de passe), lecteur, file d'attente, bibliothèque
|
||||
* et ajout de morceaux.
|
||||
* (sections, pochettes) et ajout de morceaux.
|
||||
*
|
||||
* Contexte : servi tel quel au navigateur (module ES, sans compilation) ; ne parle qu'à l'API de
|
||||
* src/web/.
|
||||
|
|
@ -12,6 +12,10 @@
|
|||
* - Le flux est lu avec fetch, et non EventSource, qui ne permet pas d'envoyer la clé.
|
||||
* - Connecté avec Discord, la session (cookie) remplace la clé : pas d'en-tête Authorization.
|
||||
* - Tout texte venu de l'API passe par escapeHtml avant d'aller dans innerHTML.
|
||||
* - Les morceaux de la file n'ont pas de pochette : elle est prise sur leur morceau de bibliothèque
|
||||
* (libraryTrackId), d'où le nouvel affichage de la file à chaque changement de la bibliothèque.
|
||||
* - L'aperçu d'une pochette choisie passe par une URL data: ; la politique de sécurité des contenus
|
||||
* (helmet) refuse les URL blob:.
|
||||
* @see README.md#jukebox
|
||||
*/
|
||||
|
||||
|
|
@ -44,6 +48,10 @@ const state = {
|
|||
queue: [],
|
||||
current: null,
|
||||
library: [],
|
||||
libraryById: new Map(),
|
||||
sections: [],
|
||||
// Sections repliées par la personne ("" : les morceaux sans section).
|
||||
collapsedSections: new Set(),
|
||||
status: "idle",
|
||||
loop: false,
|
||||
// Position du morceau en cours (ms) au moment où l'état a été reçu.
|
||||
|
|
@ -81,6 +89,7 @@ const elements = {
|
|||
libraryList: $("libraryList"),
|
||||
libraryEmpty: $("libraryEmpty"),
|
||||
librarySearch: $("librarySearch"),
|
||||
newSectionBtn: $("newSectionBtn"),
|
||||
enqueueAllBtn: $("enqueueAllBtn"),
|
||||
enqueueAllShuffledBtn: $("enqueueAllShuffledBtn"),
|
||||
uploadSection: $("uploadSection"),
|
||||
|
|
@ -90,6 +99,8 @@ const elements = {
|
|||
notesInput: $("uploadNotes"),
|
||||
permanentCheckbox: $("permanentFile"),
|
||||
enqueueCheckbox: $("enqueueFile"),
|
||||
uploadSectionField: $("uploadSectionField"),
|
||||
uploadSectionSelect: $("uploadSectionSelect"),
|
||||
uploadList: $("uploadList"),
|
||||
urlForm: $("urlForm"),
|
||||
urlInput: $("musicUrl"),
|
||||
|
|
@ -97,6 +108,15 @@ const elements = {
|
|||
heroUploadBtn: $("heroUploadBtn"),
|
||||
heroQueueBtn: $("heroQueueBtn"),
|
||||
queueSection: $("queueSection"),
|
||||
trackDialog: $("trackDialog"),
|
||||
trackForm: $("trackForm"),
|
||||
trackCoverPreview: $("trackCoverPreview"),
|
||||
trackCoverInput: $("trackCoverInput"),
|
||||
trackCoverRemoveBtn: $("trackCoverRemoveBtn"),
|
||||
trackTitleInput: $("trackTitleInput"),
|
||||
trackSectionSelect: $("trackSectionSelect"),
|
||||
trackCancelBtn: $("trackCancelBtn"),
|
||||
trackSaveBtn: $("trackSaveBtn"),
|
||||
};
|
||||
|
||||
const { setStatus, clearStatus } = createStatusManager(elements.status);
|
||||
|
|
@ -137,7 +157,7 @@ async function performRefresh() {
|
|||
apiFetch("/library"),
|
||||
]);
|
||||
applySnapshot(queueData);
|
||||
applyLibrary(libraryData.tracks || []);
|
||||
applyLibrary(libraryData);
|
||||
} catch (error) {
|
||||
handleApiError(error);
|
||||
}
|
||||
|
|
@ -145,8 +165,7 @@ async function performRefresh() {
|
|||
|
||||
async function refreshLibrary() {
|
||||
try {
|
||||
const libraryData = await apiFetch("/library");
|
||||
applyLibrary(libraryData.tracks || []);
|
||||
applyLibrary(await apiFetch("/library"));
|
||||
} catch (error) {
|
||||
handleApiError(error);
|
||||
}
|
||||
|
|
@ -189,9 +208,14 @@ function applySnapshot(snapshot) {
|
|||
renderProgress();
|
||||
}
|
||||
|
||||
function applyLibrary(tracks) {
|
||||
function applyLibrary({ tracks = [], sections = [] }) {
|
||||
state.library = tracks;
|
||||
state.libraryById = new Map(tracks.map((track) => [track.id, track]));
|
||||
state.sections = sections;
|
||||
renderLibrary();
|
||||
renderSectionChoices();
|
||||
renderCurrentTrack();
|
||||
renderQueue();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
|
@ -284,6 +308,19 @@ async function connectEvents() {
|
|||
// ---------------------------------------------------------------------------
|
||||
// Affichage
|
||||
|
||||
// Pochette d'un morceau : la sienne (bibliothèque), sinon celle de son morceau de bibliothèque.
|
||||
function coverUrlOf(track) {
|
||||
return track.coverUrl ?? state.libraryById.get(track.libraryTrackId)?.coverUrl ?? null;
|
||||
}
|
||||
|
||||
// Les adresses viennent du serveur (/covers/<nom aléatoire>) mais passent quand même par escapeHtml.
|
||||
function coverHtml(url, modifier = "") {
|
||||
const className = `cover ${modifier}`.trim();
|
||||
return url
|
||||
? `<img class="${className}" src="${escapeHtml(url)}" alt="" loading="lazy" />`
|
||||
: `<div class="${className} cover--empty" aria-hidden="true"></div>`;
|
||||
}
|
||||
|
||||
function trackMeta(track) {
|
||||
const parts = [];
|
||||
const duration = formatDuration(track.duration);
|
||||
|
|
@ -307,9 +344,12 @@ function renderCurrentTrack() {
|
|||
|
||||
elements.currentTrack.classList.remove("player-current--empty");
|
||||
elements.currentTrack.innerHTML = `
|
||||
<div class="media-item__title">${escapeHtml(track.title || track.originalName)}</div>
|
||||
<div class="media-item__meta">${trackMeta(track)}</div>
|
||||
<div class="media-item__meta">Commencé à ${formatDate(track.startedAt || track.createdAt)}</div>
|
||||
${coverHtml(coverUrlOf(track), "cover--large")}
|
||||
<div class="media-item__info">
|
||||
<div class="media-item__title">${escapeHtml(track.title || track.originalName)}</div>
|
||||
<div class="media-item__meta">${trackMeta(track)}</div>
|
||||
<div class="media-item__meta">Commencé à ${formatDate(track.startedAt || track.createdAt)}</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
|
|
@ -350,6 +390,7 @@ function renderQueue() {
|
|||
const li = document.createElement("li");
|
||||
li.className = "media-item media-item--queue";
|
||||
li.innerHTML = `
|
||||
${coverHtml(coverUrlOf(track))}
|
||||
<div class="media-item__info">
|
||||
<div class="media-item__title">${index + 1}. ${escapeHtml(track.title || track.originalName)}</div>
|
||||
<div class="media-item__meta">${trackMeta(track)}</div>
|
||||
|
|
@ -369,28 +410,114 @@ function renderQueue() {
|
|||
});
|
||||
}
|
||||
|
||||
// Groupes de la bibliothèque, dans l'ordre des sections ; « Sans section » en dernier.
|
||||
function libraryGroups() {
|
||||
const groups = state.sections.map((section) => ({ section, tracks: [] }));
|
||||
const bySection = new Map(groups.map((group) => [group.section.id, group]));
|
||||
const unsorted = { section: null, tracks: [] };
|
||||
for (const track of state.library) {
|
||||
(bySection.get(track.sectionId) ?? unsorted).tracks.push(track);
|
||||
}
|
||||
return [...groups, unsorted];
|
||||
}
|
||||
|
||||
function renderLibrary() {
|
||||
const query = elements.librarySearch.value.trim().toLowerCase();
|
||||
const tracks = state.library.filter((track) =>
|
||||
const matches = (track) =>
|
||||
`${track.title || ""} ${track.originalName || ""} ${track.artist || ""}`
|
||||
.toLowerCase()
|
||||
.includes(query)
|
||||
);
|
||||
.includes(query);
|
||||
const matchCount = state.library.filter(matches).length;
|
||||
|
||||
elements.libraryList.replaceChildren();
|
||||
elements.libraryEmpty.hidden = tracks.length > 0;
|
||||
elements.libraryEmpty.textContent =
|
||||
state.library.length === 0
|
||||
? "Aucun fichier permanent enregistré."
|
||||
: "Aucun morceau ne correspond à la recherche.";
|
||||
const isEmpty = state.library.length === 0 && state.sections.length === 0;
|
||||
elements.libraryEmpty.hidden = !isEmpty && (matchCount > 0 || !query);
|
||||
elements.libraryEmpty.textContent = isEmpty
|
||||
? "Aucun fichier permanent enregistré."
|
||||
: "Aucun morceau ne correspond à la recherche.";
|
||||
elements.enqueueAllBtn.disabled = state.library.length === 0;
|
||||
elements.enqueueAllShuffledBtn.disabled = state.library.length === 0;
|
||||
|
||||
tracks.forEach((track) => {
|
||||
// Sans section créée, la bibliothèque reste une simple liste.
|
||||
if (state.sections.length === 0) {
|
||||
elements.libraryList.append(renderTrackList(state.library.filter(matches)));
|
||||
return;
|
||||
}
|
||||
|
||||
const groups = libraryGroups();
|
||||
groups.forEach((group, index) => {
|
||||
const shown = group.tracks.filter(matches);
|
||||
if (shown.length === 0 && (query || !group.section)) return;
|
||||
elements.libraryList.append(
|
||||
renderSection(group, shown, {
|
||||
index,
|
||||
last: state.sections.length - 1,
|
||||
searching: Boolean(query),
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function renderSection({ section, tracks }, shown, { index, last, searching }) {
|
||||
const key = section?.id ?? "";
|
||||
const details = document.createElement("details");
|
||||
details.className = "library-section";
|
||||
details.open = searching || !state.collapsedSections.has(key);
|
||||
details.addEventListener("toggle", () => {
|
||||
if (searching) return;
|
||||
if (details.open) state.collapsedSections.delete(key);
|
||||
else state.collapsedSections.add(key);
|
||||
});
|
||||
|
||||
const total = tracks.reduce((sum, track) => sum + (track.duration || 0), 0);
|
||||
const count = searching ? `${shown.length} sur ${tracks.length}` : String(tracks.length);
|
||||
const disabledIfEmpty = tracks.length === 0 ? "disabled" : "";
|
||||
details.innerHTML = `
|
||||
<summary class="library-section__summary">
|
||||
<span class="library-section__name">${escapeHtml(section?.name ?? "Sans section")}</span>
|
||||
<span class="library-section__count">
|
||||
${count} morceau(x)${total ? ` • ${formatDuration(total)}` : ""}
|
||||
</span>
|
||||
</summary>
|
||||
<div class="library-section__toolbar toolbar">
|
||||
<button class="btn btn--secondary btn--small" type="button" data-action="enqueue" ${disabledIfEmpty}>Tout ajouter</button>
|
||||
<button class="btn btn--secondary btn--small" type="button" data-action="shuffle" ${disabledIfEmpty}>Mélangé</button>
|
||||
${
|
||||
section
|
||||
? `<button class="btn btn--secondary btn--small" type="button" data-action="rename">Renommer</button>
|
||||
<button class="btn btn--secondary btn--small" type="button" data-action="up" aria-label="Monter la section" title="Monter" ${index === 0 ? "disabled" : ""}>▲</button>
|
||||
<button class="btn btn--secondary btn--small" type="button" data-action="down" aria-label="Descendre la section" title="Descendre" ${index === last ? "disabled" : ""}>▼</button>
|
||||
<button class="btn btn--danger btn--small" type="button" data-action="delete">Supprimer</button>`
|
||||
: ""
|
||||
}
|
||||
</div>
|
||||
`;
|
||||
details.querySelectorAll(".library-section__toolbar button").forEach((button) => {
|
||||
button.addEventListener("click", () =>
|
||||
handleSectionAction(button.dataset.action, section, index, button)
|
||||
);
|
||||
});
|
||||
|
||||
if (tracks.length === 0) {
|
||||
const empty = document.createElement("p");
|
||||
empty.className = "hint library-section__empty";
|
||||
empty.textContent = "Aucun morceau dans cette section : choisis-la avec « Modifier » sur un morceau.";
|
||||
details.append(empty);
|
||||
} else {
|
||||
details.append(renderTrackList(shown));
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
function renderTrackList(tracks) {
|
||||
const list = document.createElement("ul");
|
||||
list.className = "list list--stack";
|
||||
for (const track of tracks) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "media-item media-item--library";
|
||||
const duration = formatDuration(track.duration);
|
||||
li.innerHTML = `
|
||||
${coverHtml(track.coverUrl)}
|
||||
<div class="media-item__info">
|
||||
<div class="media-item__title">${escapeHtml(track.title || track.originalName)}</div>
|
||||
<div class="media-item__meta">
|
||||
|
|
@ -399,7 +526,7 @@ function renderLibrary() {
|
|||
</div>
|
||||
<div class="media-item__actions">
|
||||
<button class="btn btn--small" type="button" data-action="enqueue">Ajouter</button>
|
||||
<button class="btn btn--secondary btn--small" type="button" data-action="rename">Renommer</button>
|
||||
<button class="btn btn--secondary btn--small" type="button" data-action="edit">Modifier</button>
|
||||
<button class="btn btn--danger btn--small" type="button" data-action="delete">Supprimer</button>
|
||||
</div>
|
||||
`;
|
||||
|
|
@ -408,8 +535,23 @@ function renderLibrary() {
|
|||
handleLibraryAction(button.dataset.action, track, button)
|
||||
);
|
||||
});
|
||||
elements.libraryList.appendChild(li);
|
||||
});
|
||||
list.append(li);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Listes de sections du formulaire d'ajout et de la fenêtre de modification.
|
||||
function renderSectionChoices() {
|
||||
for (const select of [elements.uploadSectionSelect, elements.trackSectionSelect]) {
|
||||
const selected = select.value;
|
||||
select.replaceChildren(new Option("Sans section", ""));
|
||||
for (const section of state.sections) {
|
||||
select.append(new Option(section.name, section.id));
|
||||
}
|
||||
select.value = state.sections.some((section) => section.id === selected) ? selected : "";
|
||||
}
|
||||
elements.uploadSectionField.hidden =
|
||||
state.sections.length === 0 || !elements.permanentCheckbox.checked;
|
||||
}
|
||||
|
||||
function renderControls() {
|
||||
|
|
@ -480,13 +622,9 @@ async function handleLibraryAction(action, track, button) {
|
|||
})
|
||||
);
|
||||
setStatus(`« ${track.title || track.originalName} » ajouté à la file`, "success");
|
||||
} else if (action === "rename") {
|
||||
const title = prompt("Nouveau titre", track.title || track.originalName);
|
||||
if (!title || !title.trim()) return;
|
||||
await withBusyButton(button, () =>
|
||||
apiFetch(`/library/${track.id}`, { method: "PATCH", body: { title: title.trim() } })
|
||||
);
|
||||
if (!state.live) await refreshLibrary();
|
||||
} else if (action === "edit") {
|
||||
openTrackEditor(track);
|
||||
return;
|
||||
} else if (action === "delete") {
|
||||
if (!confirm(`Supprimer « ${track.title || track.originalName} » de la bibliothèque ?`)) {
|
||||
return;
|
||||
|
|
@ -502,12 +640,13 @@ async function handleLibraryAction(action, track, button) {
|
|||
}
|
||||
}
|
||||
|
||||
async function enqueueAll(shuffle, button) {
|
||||
// sectionId : undefined pour toute la bibliothèque, null pour les morceaux sans section.
|
||||
async function enqueueAll(shuffle, button, sectionId) {
|
||||
try {
|
||||
const { tracks } = await withBusyButton(button, () =>
|
||||
apiFetch("/library/enqueue-all", {
|
||||
method: "POST",
|
||||
body: { shuffle, requestedBy: requesterName() },
|
||||
body: { shuffle, sectionId, requestedBy: requesterName() },
|
||||
})
|
||||
);
|
||||
setStatus(`${tracks.length} morceau(x) ajouté(s) à la file`, "success");
|
||||
|
|
@ -517,8 +656,143 @@ async function enqueueAll(shuffle, button) {
|
|||
}
|
||||
}
|
||||
|
||||
async function createSection(button) {
|
||||
const name = prompt("Nom de la nouvelle section");
|
||||
if (!name || !name.trim()) return;
|
||||
try {
|
||||
await withBusyButton(button, () =>
|
||||
apiFetch("/library/sections", { method: "POST", body: { name: name.trim() } })
|
||||
);
|
||||
if (!state.live) await refreshLibrary();
|
||||
} catch (error) {
|
||||
setStatus(`Création de la section impossible : ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
|
||||
// section vaut null pour le groupe « Sans section », qui n'a que les actions d'ajout.
|
||||
async function handleSectionAction(action, section, index, button) {
|
||||
try {
|
||||
if (action === "enqueue" || action === "shuffle") {
|
||||
await enqueueAll(action === "shuffle", button, section?.id ?? null);
|
||||
return;
|
||||
}
|
||||
if (action === "rename") {
|
||||
const name = prompt("Nouveau nom de la section", section.name);
|
||||
if (!name || !name.trim()) return;
|
||||
await withBusyButton(button, () =>
|
||||
apiFetch(`/library/sections/${section.id}`, {
|
||||
method: "PATCH",
|
||||
body: { name: name.trim() },
|
||||
})
|
||||
);
|
||||
} else if (action === "up" || action === "down") {
|
||||
const position = index + (action === "up" ? -1 : 1);
|
||||
await withBusyButton(button, () =>
|
||||
apiFetch(`/library/sections/${section.id}`, { method: "PATCH", body: { position } })
|
||||
);
|
||||
} else if (action === "delete") {
|
||||
if (
|
||||
!confirm(
|
||||
`Supprimer la section « ${section.name} » ? Ses morceaux restent dans la bibliothèque, sans section.`
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
await withBusyButton(button, () =>
|
||||
apiFetch(`/library/sections/${section.id}`, { method: "DELETE" })
|
||||
);
|
||||
}
|
||||
if (!state.live) await refreshLibrary();
|
||||
} catch (error) {
|
||||
setStatus(`Action sur la section impossible : ${error.message}`, "error");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Fenêtre de modification d'un morceau (titre, section, pochette)
|
||||
|
||||
const MAX_COVER_SIZE = 10 * 1024 * 1024;
|
||||
let editedTrack = null;
|
||||
let removeCover = false;
|
||||
|
||||
function showCoverPreview(url) {
|
||||
const preview = elements.trackCoverPreview;
|
||||
preview.classList.toggle("cover--empty", !url);
|
||||
preview.style.backgroundImage = url ? `url("${url}")` : "";
|
||||
}
|
||||
|
||||
function openTrackEditor(track) {
|
||||
editedTrack = track;
|
||||
removeCover = false;
|
||||
elements.trackTitleInput.value = track.title || track.originalName;
|
||||
renderSectionChoices();
|
||||
elements.trackSectionSelect.value = track.sectionId ?? "";
|
||||
elements.trackCoverInput.value = "";
|
||||
elements.trackCoverRemoveBtn.hidden = !track.coverUrl;
|
||||
showCoverPreview(track.coverUrl);
|
||||
elements.trackDialog.showModal();
|
||||
}
|
||||
|
||||
function previewChosenCover() {
|
||||
const file = elements.trackCoverInput.files[0];
|
||||
if (!file) {
|
||||
showCoverPreview(removeCover ? null : editedTrack?.coverUrl);
|
||||
return;
|
||||
}
|
||||
if (file.size > MAX_COVER_SIZE) {
|
||||
setStatus("Image trop lourde : 10 Mo au plus", "error");
|
||||
elements.trackCoverInput.value = "";
|
||||
return;
|
||||
}
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener("load", () => showCoverPreview(reader.result));
|
||||
reader.readAsDataURL(file);
|
||||
elements.trackCoverRemoveBtn.hidden = false;
|
||||
}
|
||||
|
||||
function clearChosenCover() {
|
||||
removeCover = true;
|
||||
elements.trackCoverInput.value = "";
|
||||
elements.trackCoverRemoveBtn.hidden = true;
|
||||
showCoverPreview(null);
|
||||
}
|
||||
|
||||
async function saveTrackEditor(event) {
|
||||
event.preventDefault();
|
||||
const track = editedTrack;
|
||||
if (!track) return;
|
||||
|
||||
const changes = {};
|
||||
const title = elements.trackTitleInput.value.trim();
|
||||
if (title && title !== (track.title || track.originalName)) changes.title = title;
|
||||
const sectionId = elements.trackSectionSelect.value || null;
|
||||
if (sectionId !== (track.sectionId ?? null)) changes.sectionId = sectionId;
|
||||
const coverFile = elements.trackCoverInput.files[0];
|
||||
|
||||
try {
|
||||
await withBusyButton(elements.trackSaveBtn, async () => {
|
||||
if (Object.keys(changes).length > 0) {
|
||||
await apiFetch(`/library/${track.id}`, { method: "PATCH", body: changes });
|
||||
}
|
||||
if (coverFile) {
|
||||
const data = new FormData();
|
||||
data.append("cover", coverFile);
|
||||
await apiFetch(`/library/${track.id}/cover`, { method: "PUT", body: data });
|
||||
} else if (removeCover && track.coverUrl) {
|
||||
await apiFetch(`/library/${track.id}/cover`, { method: "DELETE" });
|
||||
}
|
||||
});
|
||||
elements.trackDialog.close();
|
||||
if (!state.live) await refreshLibrary();
|
||||
} catch (error) {
|
||||
// La fenêtre reste ouverte : la personne peut corriger (autre image…) et réessayer.
|
||||
setStatus(`Modification impossible : ${error.message}`, "error");
|
||||
if (!state.live) await refreshLibrary();
|
||||
}
|
||||
}
|
||||
|
||||
// Envoi avec XMLHttpRequest : contrairement à fetch, il indique la progression de l'envoi.
|
||||
function uploadFile(file, { permanent, enqueue, title, onProgress }) {
|
||||
function uploadFile(file, { permanent, enqueue, section, title, onProgress }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const data = new FormData();
|
||||
data.append("file", file);
|
||||
|
|
@ -526,6 +800,7 @@ function uploadFile(file, { permanent, enqueue, title, onProgress }) {
|
|||
data.append("enqueue", String(enqueue));
|
||||
data.append("uploader", requesterName());
|
||||
if (title) data.append("notes", title);
|
||||
if (permanent && section) data.append("section", section);
|
||||
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("POST", "/api/uploads");
|
||||
|
|
@ -584,6 +859,7 @@ async function handleUpload(event) {
|
|||
const options = {
|
||||
permanent: elements.permanentCheckbox.checked,
|
||||
enqueue: elements.enqueueCheckbox.checked,
|
||||
section: elements.uploadSectionSelect.value,
|
||||
};
|
||||
if (!options.permanent && !options.enqueue) {
|
||||
setStatus("Un fichier temporaire doit être ajouté à la file d'attente", "error");
|
||||
|
|
@ -638,6 +914,7 @@ async function handleUrlSubmit(event) {
|
|||
url,
|
||||
permanent: elements.permanentCheckbox.checked,
|
||||
enqueue: elements.enqueueCheckbox.checked,
|
||||
section: elements.uploadSectionSelect.value || undefined,
|
||||
uploader: requesterName(),
|
||||
},
|
||||
})
|
||||
|
|
@ -737,6 +1014,16 @@ function bindEvents() {
|
|||
});
|
||||
|
||||
elements.librarySearch.addEventListener("input", renderLibrary);
|
||||
elements.newSectionBtn.addEventListener("click", () => createSection(elements.newSectionBtn));
|
||||
elements.permanentCheckbox.addEventListener("change", renderSectionChoices);
|
||||
|
||||
elements.trackForm.addEventListener("submit", saveTrackEditor);
|
||||
elements.trackCancelBtn.addEventListener("click", () => elements.trackDialog.close());
|
||||
elements.trackCoverInput.addEventListener("change", previewChosenCover);
|
||||
elements.trackCoverRemoveBtn.addEventListener("click", clearChosenCover);
|
||||
elements.trackDialog.addEventListener("close", () => {
|
||||
editedTrack = null;
|
||||
});
|
||||
elements.enqueueAllBtn.addEventListener("click", () =>
|
||||
enqueueAll(false, elements.enqueueAllBtn)
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue