From 1c9a6711b313f2d7e0215b92ba909581537813c7 Mon Sep 17 00:00:00 2001 From: Mischa Date: Fri, 19 Jun 2026 15:11:29 +0200 Subject: [PATCH] fix: slugify uploaded GPX filename before sending to API --- themes/intotheeast/templates/gpx-manager.html.twig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/themes/intotheeast/templates/gpx-manager.html.twig b/themes/intotheeast/templates/gpx-manager.html.twig index 5d8994d..3ed28d5 100644 --- a/themes/intotheeast/templates/gpx-manager.html.twig +++ b/themes/intotheeast/templates/gpx-manager.html.twig @@ -54,6 +54,14 @@ function formatSize(bytes) { return (bytes / 1024).toFixed(0) + ' KB'; } +function slugifyFilename(filename) { + const lastDot = filename.lastIndexOf('.'); + const name = lastDot > 0 ? filename.slice(0, lastDot) : filename; + const ext = lastDot > 0 ? filename.slice(lastDot).toLowerCase() : ''; + const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, ''); + return slug + ext; +} + function formatDate(iso) { return new Date(iso).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' }); } @@ -131,7 +139,7 @@ function initUpload(formEl) { btn.disabled = true; const fd = new FormData(); - fd.append('file', file); + fd.append('file', new File([file], slugifyFilename(file.name), { type: file.type })); const res = await apiFetch(`${API}/pages${route}/media`, { method: 'POST', body: fd }); btn.disabled = false;