Add CSV file upload and auto-delimiter detection for pilot import

Allows uploading a CSV file directly instead of only pasting text, and
auto-detects comma vs semicolon separators to support more locales.
This commit is contained in:
Jan Meinl
2026-08-19 15:32:26 +02:00
parent 4b5f0eb326
commit 65bb2b351f
10 changed files with 97 additions and 16 deletions
+12 -3
View File
@@ -48,11 +48,20 @@ const API = {
createPilot: (id, b) => api("POST", `/api/competitions/${id}/pilots`, b),
updatePilot: (id, pid, b) => api("PATCH", `/api/competitions/${id}/pilots/${pid}`, b),
deletePilot: (id, pid) => api("DELETE", `/api/competitions/${id}/pilots/${pid}`),
importPilots: async (id, csv) => {
importPilots: async (id, data) => {
let body, headers = {};
if (data instanceof File) {
const form = new FormData();
form.append("file", data);
body = form;
} else {
headers["Content-Type"] = "text/csv";
body = data;
}
const res = await fetch(apiURL(`/api/competitions/${id}/pilots/import`), {
method: "POST",
headers: { "Content-Type": "text/csv" },
body: csv,
headers,
body,
credentials: "include",
});
if (!res.ok) throw new Error("import_failed");