Add YAML support to events GET endpoint

This commit is contained in:
D. Berge
2023-10-23 19:24:03 +02:00
parent 025f3f774d
commit b5aafe42ad
2 changed files with 17 additions and 0 deletions

View File

@@ -1,12 +1,15 @@
const json = require('./json'); const json = require('./json');
const yaml = require('./yaml');
const geojson = require('./geojson'); const geojson = require('./geojson');
const seis = require('./seis'); const seis = require('./seis');
const csv = require('./csv'); const csv = require('./csv');
module.exports = async function (req, res, next) { module.exports = async function (req, res, next) {
try { try {
const handlers = { const handlers = {
"application/json": json, "application/json": json,
"application/yaml": yaml,
"application/geo+json": geojson, "application/geo+json": geojson,
"application/vnd.seis+json": seis, "application/vnd.seis+json": seis,
"text/csv": csv "text/csv": csv

View File

@@ -0,0 +1,14 @@
const YAML = require('yaml');
const { event } = require('../../../../lib/db');
const yaml = async function (req, res, next) {
try {
const response = await event.list(req.params.project, req.query);
res.status(200).send(YAML.stringify(response));
next();
} catch (err) {
next(err);
}
};
module.exports = yaml;