From 08feda9af6e1f229d9e635fb7a20d62f2116fca3 Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Mon, 9 Feb 2026 10:58:01 +0300 Subject: [PATCH] export: use filename from Content-Disposition header in browser Fix issue where frontend was ignoring server's Content-Disposition header and using only config name + '.csv' for exported files. Added getFilenameFromResponse() helper to extract proper filename from Content-Disposition header and use it for downloaded files. Applied to both: - exportCSV() function - exportCSVWithCustomPrice() function Now files are downloaded with correct format: YYYY-MM-DD (PROJECT-NAME) BOM.csv Co-Authored-By: Claude Haiku 4.5 --- web/templates/index.html | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/templates/index.html b/web/templates/index.html index 1979b56..7d1d645 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -1716,6 +1716,14 @@ async function saveConfig(showNotification = true) { } } +// Helper function to extract filename from Content-Disposition header +function getFilenameFromResponse(resp) { + const contentDisposition = resp.headers.get('content-disposition'); + if (!contentDisposition) return null; + const matches = contentDisposition.match(/filename="?([^"]+)"?/); + return matches && matches[1] ? matches[1] : null; +} + async function exportCSV() { if (cart.length === 0) return; @@ -1740,7 +1748,7 @@ async function exportCSV() { const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; - a.download = (configName || 'config') + '.csv'; + a.download = getFilenameFromResponse(resp) || (configName || 'config') + '.csv'; a.click(); window.URL.revokeObjectURL(url); } catch(e) { @@ -1993,7 +2001,7 @@ async function exportCSVWithCustomPrice() { const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; - a.download = (configName || 'config') + '.csv'; + a.download = getFilenameFromResponse(resp) || (configName || 'config') + '.csv'; a.click(); window.URL.revokeObjectURL(url); } catch(e) {