@a11ywatch/core
Version:
a11ywatch central API
65 lines • 3.76 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadToExcel = void 0;
const exceljs_1 = __importDefault(require("exceljs"));
const message_1 = require("../../web/messages/message");
const downloadToExcel = (_req, res, data) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
const source = (data === null || data === void 0 ? void 0 : data.website) ? data === null || data === void 0 ? void 0 : data.website : data;
if (!source) {
res.status(message_1.StatusCode.Ok).send();
return;
}
try {
const workbook = new exceljs_1.default.Workbook();
const pageName = (_a = source === null || source === void 0 ? void 0 : source.url) !== null && _a !== void 0 ? _a : "Website";
const worksheet = workbook.addWorksheet(`${source === null || source === void 0 ? void 0 : source.domain} WCAG Audit`, {
headerFooter: {
firstHeader: `Accessibility score - ${(_b = source.issuesInfo) === null || _b === void 0 ? void 0 : _b.accessScore}`,
firstFooter: `Test ran ${source === null || source === void 0 ? void 0 : source.lastScanDate}`,
},
});
worksheet.columns = [
{ header: "Code", key: "code", width: 14, checked: 0 },
{ header: "Type", key: "type", width: 5, checked: 0 },
{ header: "Message", key: "message", width: 30, checked: 0 },
{ header: "Context", key: "context", width: 40, checked: 0 },
{ header: "Selector", key: "selector", width: 30, checked: 0 },
{ header: "Recurrence", key: "recurrence", width: 30, checked: 0 },
{
header: "Audit",
key: "checked",
width: 5,
outlineLevel: 1,
checked: 0,
},
];
const rowIssues = ((_c = source === null || source === void 0 ? void 0 : source.issue) === null || _c === void 0 ? void 0 : _c.length) ? source.issue : source === null || source === void 0 ? void 0 : source.issues;
const rows = (rowIssues !== null && rowIssues !== void 0 ? rowIssues : []).map((items) => (Object.assign(Object.assign({}, items), { style: { font: { name: "Helvetica" } } })));
if (rows.length) {
worksheet.addRows(rows);
}
res.header("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
res.header("Content-Disposition", "attachment; filename=" + `${pageName}-${source === null || source === void 0 ? void 0 : source.lastScanDate}-audit.xlsx`);
const buffer = yield workbook.xlsx.writeBuffer();
res.status(message_1.StatusCode.Ok).send(buffer);
}
catch (e) {
console.error(e);
res.status(message_1.StatusCode.Error).send();
}
});
exports.downloadToExcel = downloadToExcel;
//# sourceMappingURL=download-to-excel.js.map