Added GPX download route
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
bfec14ba8a
commit
f25c8ef4b9
@ -38,6 +38,36 @@ module.exports = (fastify, opts, done) => {
|
|||||||
return reply;
|
return reply;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
fastify.get("/gpx/:id", async (req, reply) => {
|
||||||
|
if (req.params.id == undefined)
|
||||||
|
return reply.code(400).send({ error: "No ID query parameter" });
|
||||||
|
|
||||||
|
fastify.level.db.get(req.params.id, (err, val) => {
|
||||||
|
if (err) {
|
||||||
|
console.warn(err);
|
||||||
|
reply.code(500).send();
|
||||||
|
} else {
|
||||||
|
let file = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" version="1.1" creator="EMTAC BTGPS Trine II DataLog Dump 1.0 - http://www.ayeltd.biz" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">'
|
||||||
|
const data = JSON.parse(val);
|
||||||
|
const gen_wpt = (name,desc,latlon,icon="Flag") => `<wpt lat="${latlon[0]}" lon="${latlon[1]}"><ele>0</ele><name>${name}</name><cmt>-</cmt><desc>${desc}</desc><sym>${icon}</sym></wpt>`
|
||||||
|
data.main.array.forEach(a => {
|
||||||
|
file+= gen_wpt(a.hotel.name, a.hotel.notes, a.hotel.latlon, icon="Hotel");
|
||||||
|
a.places.restaurants.array.forEach(b => {
|
||||||
|
file+= gen_wpt(b.name, b.notes, b.latlon, icon="Restaurant");
|
||||||
|
});
|
||||||
|
a.places.activities.array.forEach(b => {
|
||||||
|
file+= gen_wpt(b.name, b.notes, b.latlon, icon="Tree");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
file+="</gpx>";
|
||||||
|
reply.header('Content-Type', 'application/gpx+xml');
|
||||||
|
reply.header('Content-Disposition', `attachment; filename=${req.params.id}.gpx`);
|
||||||
|
reply.send(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return reply;
|
||||||
|
});
|
||||||
|
|
||||||
fastify.get("/:id", async (req, reply) => {
|
fastify.get("/:id", async (req, reply) => {
|
||||||
if (req.params.id == undefined)
|
if (req.params.id == undefined)
|
||||||
return reply.code(400).send({ error: "No ID query parameter" });
|
return reply.code(400).send({ error: "No ID query parameter" });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user