Better nominatim
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
soraefir
2025-02-25 01:38:34 +01:00
parent b554eba76c
commit 0cc9d235ed
7 changed files with 149 additions and 195 deletions

View File

@@ -6,7 +6,7 @@ module.exports = (fastify, opts, done) => {
url.searchParams.append('query', req.params.id)
url.searchParams.append('limit', 16)
url.searchParams.append('type', 'schedule')
fetch(url).then((res) => reply.send(res.data));
fetch(url).then((res) => reply.send(res.json()));
} else {
return reply.send([]);
}
@@ -14,10 +14,20 @@ module.exports = (fastify, opts, done) => {
});
fastify.get("/place/:id", async (req, reply) => {
if (req.params.id) {
const url = new URL("https://nominatim.openstreetmap.org/");
const url = new URL("https://nominatim.openstreetmap.org/search");
url.searchParams.append('format', 'jsonv2')
url.searchParams.append('q', req.params.id)
fetch(url).then((res) => reply.send(res.data));
let bb = JSON.parse(req.query.bb)
if(bb){
url.searchParams.append('viewbox', `${bb[0][0]},${bb[0][1]},${bb[1][0]},${bb[1][1]}`)
url.searchParams.append('bounded', 1)
}
fetch(url).then((res) => {
if( !res.ok) throw new Error("Nominatim Error")
return res.json()
}).then(res=>{
reply.send(res)});
} else {
return reply.send([]);
}