geolocation api rate-limit: add per-provider prefix to cached response, refactor geocoding provider code

This commit is contained in:
sedum
2023-01-19 12:06:23 +01:00
parent 6ee96fb07c
commit cc4bb69667
5 changed files with 179 additions and 133 deletions

View File

@@ -0,0 +1,23 @@
module.exports = {
commonName: 'Nominatim',
DEFAULT_ENDPOINT: 'https://nominatim.openstreetmap.org/search',
endpoint: (req, res) => {
return res.locals.settings.geocoding_provider || this.DEFAULT_ENDPOINT
},
getParams (req, res) {
const countrycodes = res.locals.settings.geocoding_countrycodes || []
const details = req.params.place_details
return {
countrycodes: countrycodes.join(','),
q: details,
limit: 3,
format: 'json',
addressdetails: 1,
namedetails: 1,
}
},
}

View File

@@ -0,0 +1,18 @@
module.exports = {
commonName: 'Photon',
DEFAULT_ENDPOINT: 'https://photon.komoot.io/api/',
endpoint: (req, res) => {
return res.locals.settings.geocoding_provider || this.DEFAULT_ENDPOINT
},
getParams (req, res) {
const details = req.params.place_details
return {
q: details,
limit: 3,
}
}
}