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:
+12
-3
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user