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;