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 <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user