mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:17:08 +00:00
Add binary format middleware for sequence data.
It responds to the MIME type: application/dougal-map-sequence+octet-stream
This commit is contained in:
61
lib/www/server/api/middleware/sequence/get/binary.js
Normal file
61
lib/www/server/api/middleware/sequence/get/binary.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
const { sequence } = require('../../../../lib/db');
|
||||||
|
const { MSGTYPE, encode } = require('../../../../lib/binary');
|
||||||
|
|
||||||
|
module.exports = async function (req, res, next) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const json = await sequence.get(req.params.project, req.params.sequence, req.query);
|
||||||
|
|
||||||
|
let msgType, geometry, error;
|
||||||
|
switch (req.query.geometry) {
|
||||||
|
case "F":
|
||||||
|
case "FINAL":
|
||||||
|
msgType = MSGTYPE.FINAL_OPT;
|
||||||
|
geometry = "geometryfinal";
|
||||||
|
error = "errorfinal";
|
||||||
|
break;
|
||||||
|
case "f":
|
||||||
|
case "final":
|
||||||
|
msgType = MSGTYPE.FINAL;
|
||||||
|
geometry = "geometryfinal";
|
||||||
|
error = "errorfinal";
|
||||||
|
break;
|
||||||
|
case "R":
|
||||||
|
case "RAW":
|
||||||
|
msgType = MSGTYPE.RAW_OPT;
|
||||||
|
geometry = "geometryraw";
|
||||||
|
error = "errorraw";
|
||||||
|
break;
|
||||||
|
case "r":
|
||||||
|
case "raw":
|
||||||
|
msgType = MSGTYPE.RAW;
|
||||||
|
geometry = "geometryraw";
|
||||||
|
error = "errorraw";
|
||||||
|
break;
|
||||||
|
case "P":
|
||||||
|
case "PREPLOT":
|
||||||
|
msgType = MSGTYPE.PREPLOT_RAWERROR_OPT;
|
||||||
|
geometry = "geometrypreplot";
|
||||||
|
error = ["errorfinal", "errorraw"];
|
||||||
|
break;
|
||||||
|
case "p":
|
||||||
|
case "preplot":
|
||||||
|
default:
|
||||||
|
msgType = MSGTYPE.PREPLOT;
|
||||||
|
geometry = "geometrypreplot";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
const endianness = req.query.endianness != "big";
|
||||||
|
|
||||||
|
const data = encode(json, geometry, error, msgType, endianness);
|
||||||
|
console.log("bundle", data);
|
||||||
|
|
||||||
|
res.status(200).send(Buffer.from(data));
|
||||||
|
next();
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
const json = require('./json');
|
const json = require('./json');
|
||||||
const geojson = require('./geojson');
|
const geojson = require('./geojson');
|
||||||
|
const binary = require('./binary');
|
||||||
|
|
||||||
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/geo+json": geojson,
|
"application/geo+json": geojson,
|
||||||
|
"application/dougal-map-sequence+octet-stream": binary
|
||||||
};
|
};
|
||||||
|
|
||||||
const mimetype = (handlers[req.query.mime] && req.query.mime) || req.accepts(Object.keys(handlers));
|
const mimetype = (handlers[req.query.mime] && req.query.mime) || req.accepts(Object.keys(handlers));
|
||||||
|
|||||||
Reference in New Issue
Block a user