Files
dougal-software/lib/www/server/api/middleware/event/get/seis.js
D. Berge b0f4559b83 Allow direct downloading of sequence reports.
If the `download` or `d` query parameter is supplied (even
without any value), the response will include a
`Content-Disposition: attachment` header. A filename will
also be suggested.
2021-05-15 17:10:28 +02:00

23 lines
761 B
JavaScript

const { event, sequence } = require('../../../../lib/db');
const { transform } = require('../../../../lib/sse');
const seis = async function (req, res, next) {
try {
const query = req.query;
query.sequence = req.params.sequence;
const events = await event.list(req.params.project, query);
const sequences = await sequence.list(req.params.project, query);
const response = transform(events, sequences, {projectId: req.params.project});
if ("download" in query || "d" in query) {
const filename = `${req.params.project}-seq${query.sequence.padStart(3, "0")}.json`;
res.set("Content-Disposition", `attachment; filename="${filename}"`);
}
res.status(200).send(response);
next();
} catch (err) {
next(err);
}
};
module.exports = seis;