mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 09:47:08 +00:00
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.
33 lines
850 B
JavaScript
33 lines
850 B
JavaScript
|
|
const { event } = require('../../../../lib/db');
|
|
|
|
const geojson = 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 response = {
|
|
type: "FeatureCollection",
|
|
features: events.filter(event => event.geometry).map(event => {
|
|
const feature = {
|
|
type: "Feature",
|
|
geometry: event.geometry,
|
|
properties: event
|
|
};
|
|
delete feature.properties.geometry;
|
|
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) {
|
|
next(err);
|
|
}
|
|
}
|
|
|
|
module.exports = geojson;
|