larxius commited on
Commit
8873e1f
·
verified ·
1 Parent(s): fda7e27

Update frontend/src/pages/ReportsHistory.jsx

Browse files
frontend/src/pages/ReportsHistory.jsx CHANGED
@@ -78,8 +78,27 @@ export const ReportsHistory = () => {
78
  const blob = await res.blob();
79
  const url = window.URL.createObjectURL(blob);
80
  const a = document.createElement('a');
81
- a.href = url;
82
- a.download = `LarShield_Report_${scanId.substring(0, 8)}.pdf`;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  document.body.appendChild(a);
84
  a.click();
85
  a.remove();
 
78
  const blob = await res.blob();
79
  const url = window.URL.createObjectURL(blob);
80
  const a = document.createElement('a');
81
+ let filename = '';
82
+ const disposition = res.headers.get('Content-Disposition');
83
+ if (disposition && disposition.includes('filename=')) {
84
+ const match = disposition.match(/filename="?([^";]+)"?/);
85
+ if (match && match[1]) {
86
+ filename = match[1];
87
+ }
88
+ }
89
+
90
+ if (!filename) {
91
+ const scanItem = scans.find(s => s.id === scanId);
92
+ const orgName = scanItem?.org_name || scanItem?.organization_name || 'Global';
93
+ const cleanOrg = orgName.replace(/[^\w]/g, '') || 'Organization';
94
+ const dateObj = new Date(scanItem?.completed_at || scanItem?.started_at || Date.now());
95
+ const day = String(dateObj.getDate()).padStart(2, '0');
96
+ const month = String(dateObj.getMonth() + 1).padStart(2, '0');
97
+ const year = dateObj.getFullYear();
98
+ filename = `LarShield_${cleanOrg}_Report_${day}${month}${year}.pdf`;
99
+ }
100
+
101
+ a.download = filename;
102
  document.body.appendChild(a);
103
  a.click();
104
  a.remove();