refactor: replace exceljs with write-excel-file for analytics export
Build & Push Docker Image / build (push) Successful in 3m57s
Build & Push Docker Image / build (push) Successful in 3m57s
exceljs (latest 4.4.0) ships years-old transitive dependencies that npm flags as deprecated on every install (rimraf 2, glob 7, inflight, fstream, lodash.isequal) and needed a uuid override for a security advisory. It was only used for the single-sheet analytics XLSX export, which write-excel-file covers with the same output (column widths, bold/grey header, formula-injection escaping). Removes the now-unneeded exceljs uuid override. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Generated
+20
-790
File diff suppressed because it is too large
Load Diff
+1
-6
@@ -19,7 +19,6 @@
|
|||||||
"concurrently": "^9.0.0",
|
"concurrently": "^9.0.0",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
"dotenv": "^17.3.1",
|
"dotenv": "^17.3.1",
|
||||||
"exceljs": "^4.4.0",
|
|
||||||
"express": "^5.2.1",
|
"express": "^5.2.1",
|
||||||
"express-rate-limit": "^8.5.2",
|
"express-rate-limit": "^8.5.2",
|
||||||
"flatpickr": "^4.6.13",
|
"flatpickr": "^4.6.13",
|
||||||
@@ -38,6 +37,7 @@
|
|||||||
"react-hot-toast": "^2.4.0",
|
"react-hot-toast": "^2.4.0",
|
||||||
"react-router-dom": "^7.15.1",
|
"react-router-dom": "^7.15.1",
|
||||||
"uuid": "^14.0.0",
|
"uuid": "^14.0.0",
|
||||||
|
"write-excel-file": "^4.1.1",
|
||||||
"xml2js": "^0.6.0"
|
"xml2js": "^0.6.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -49,11 +49,6 @@
|
|||||||
"tailwindcss": "^4.3.0",
|
"tailwindcss": "^4.3.0",
|
||||||
"vite": "^8.0.0"
|
"vite": "^8.0.0"
|
||||||
},
|
},
|
||||||
"overrides": {
|
|
||||||
"exceljs": {
|
|
||||||
"uuid": "^11.1.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"allowScripts": {
|
"allowScripts": {
|
||||||
"better-sqlite3@12.11.1": true
|
"better-sqlite3@12.11.1": true
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-18
@@ -1,6 +1,6 @@
|
|||||||
import { Router, json } from 'express';
|
import { Router, json } from 'express';
|
||||||
import crypto from 'crypto';
|
import crypto from 'crypto';
|
||||||
import ExcelJS from 'exceljs';
|
import writeXlsxFile from 'write-excel-file/node';
|
||||||
import PDFDocument from 'pdfkit';
|
import PDFDocument from 'pdfkit';
|
||||||
import { getDb } from '../config/database.js';
|
import { getDb } from '../config/database.js';
|
||||||
import { authenticateToken } from '../middleware/auth.js';
|
import { authenticateToken } from '../middleware/auth.js';
|
||||||
@@ -246,26 +246,24 @@ router.get('/:id/export/:format', authenticateToken, async (req, res) => {
|
|||||||
|
|
||||||
if (format === 'xlsx') {
|
if (format === 'xlsx') {
|
||||||
// Prefix-escape strings that would otherwise be evaluated as formulas.
|
// Prefix-escape strings that would otherwise be evaluated as formulas.
|
||||||
const sanitizeXlsx = (r) => {
|
const sanitizeXlsx = (v) =>
|
||||||
const out = {};
|
(typeof v === 'string' && /^[=+\-@\t\r]/.test(v)) ? "'" + v : v;
|
||||||
for (const k of Object.keys(r)) {
|
|
||||||
const v = r[k];
|
const headerRow = COLUMNS.map(c => ({
|
||||||
out[k] = (typeof v === 'string' && /^[=+\-@\t\r]/.test(v)) ? "'" + v : v;
|
value: c.header,
|
||||||
}
|
fontWeight: 'bold',
|
||||||
return out;
|
backgroundColor: '#e0e0e0',
|
||||||
};
|
}));
|
||||||
const workbook = new ExcelJS.Workbook();
|
const dataRows = rows.map(r => COLUMNS.map(c => ({ value: sanitizeXlsx(r[c.key]) })));
|
||||||
const sheet = workbook.addWorksheet('Analytics');
|
|
||||||
sheet.columns = COLUMNS;
|
const buffer = await writeXlsxFile([headerRow, ...dataRows], {
|
||||||
rows.forEach(r => sheet.addRow(sanitizeXlsx(r)));
|
columns: COLUMNS.map(c => ({ width: c.width })),
|
||||||
// Style header row
|
sheet: 'Analytics',
|
||||||
sheet.getRow(1).font = { bold: true };
|
}).toBuffer();
|
||||||
sheet.getRow(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } };
|
|
||||||
|
|
||||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${safeName}.xlsx"`);
|
res.setHeader('Content-Disposition', `attachment; filename="${safeName}.xlsx"`);
|
||||||
await workbook.xlsx.write(res);
|
return res.send(buffer);
|
||||||
return res.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format === 'pdf') {
|
if (format === 'pdf') {
|
||||||
|
|||||||
Reference in New Issue
Block a user