mirror of
https://github.com/pa11y/pa11y-dashboard.git
synced 2025-09-24 22:31:15 +00:00
Add CSV download for results
This commit is contained in:
42
route/result/download.js
Normal file
42
route/result/download.js
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
var moment = require('moment');
|
||||
|
||||
module.exports = route;
|
||||
|
||||
// Route definition
|
||||
function route (app) {
|
||||
|
||||
app.express.get('/:id/:rid.csv', function (req, res, next) {
|
||||
app.webservice.task(req.params.id).get({}, function (err, task) {
|
||||
if (err) {
|
||||
return next();
|
||||
}
|
||||
app.webservice
|
||||
.task(req.params.id)
|
||||
.result(req.params.rid)
|
||||
.get({full: true}, function (err, result) {
|
||||
if (err) {
|
||||
return next();
|
||||
}
|
||||
var rows = ['"code", "message", "type"'];
|
||||
result.results.forEach(function (msg) {
|
||||
rows.push([
|
||||
JSON.stringify(msg.code),
|
||||
JSON.stringify(msg.message),
|
||||
JSON.stringify(msg.type)
|
||||
].join(', '));
|
||||
});
|
||||
res.attachment([
|
||||
'pa11y--',
|
||||
task.url.replace(/^https?:\/\//i, '').replace(/\/$/, '').replace(/[^a-z0-9\.\-\_]+/gi, '-') + '--',
|
||||
task.standard.toLowerCase() + '--',
|
||||
moment(result.date).format('YYYY-MM-DD'),
|
||||
'.csv'
|
||||
].join(''));
|
||||
res.send(rows.join('\n'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}
|
Reference in New Issue
Block a user