mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
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.
This commit is contained in:
@@ -18,6 +18,10 @@ const geojson = async function (req, res, next) {
|
||||
return feature;
|
||||
})
|
||||
};
|
||||
if ("download" in query || "d" in query) {
|
||||
const filename = `${req.params.project}-seq${query.sequence.padStart(3, "0")}.geojson`;
|
||||
res.set("Content-Disposition", `attachment; filename="${filename}"`);
|
||||
}
|
||||
res.status(200).send(response);
|
||||
next();
|
||||
} catch (err) {
|
||||
|
||||
@@ -13,6 +13,11 @@ const html = async function (req, res, next) {
|
||||
const template = templates[0].template;
|
||||
|
||||
const response = await render(seis, template);
|
||||
|
||||
if ("download" in query || "d" in query) {
|
||||
const filename = `${req.params.project}-seq${query.sequence.padStart(3, "0")}.html`;
|
||||
res.set("Content-Disposition", `attachment; filename="${filename}"`);
|
||||
}
|
||||
res.status(200).send(response);
|
||||
next();
|
||||
} catch (err) {
|
||||
|
||||
@@ -6,6 +6,10 @@ const json = async function (req, res, next) {
|
||||
const query = req.query;
|
||||
query.sequence = req.params.sequence;
|
||||
const response = await event.list(req.params.project, query);
|
||||
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) {
|
||||
|
||||
@@ -26,6 +26,10 @@ const pdf = async function (req, res, next) {
|
||||
await fs.writeFile(fname, html);
|
||||
const pdf = Buffer.from(await url2pdf("file://"+fname), "base64");
|
||||
|
||||
if ("download" in query || "d" in query) {
|
||||
const filename = `${req.params.project}-seq${query.sequence.padStart(3, "0")}.pdf`;
|
||||
res.set("Content-Disposition", `attachment; filename="${filename}"`);
|
||||
}
|
||||
res.status(200).send(pdf);
|
||||
next();
|
||||
} catch (err) {
|
||||
|
||||
@@ -8,6 +8,10 @@ const seis = async function (req, res, next) {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user