geolocation api rate-limit: split cache instance, one for each provider

This commit is contained in:
sedum
2023-01-21 01:18:16 +01:00
parent c50d369de9
commit ad3ace1e7e
3 changed files with 26 additions and 18 deletions

View File

@@ -1,10 +1,13 @@
const cache = require('memory-cache')
const providerCache = new cache.Cache()
module.exports = {
const nominatim = {
commonName: 'Nominatim',
DEFAULT_ENDPOINT: 'https://nominatim.openstreetmap.org/search',
endpoint: (req, res) => {
return res.locals.settings.geocoding_provider || this.DEFAULT_ENDPOINT
return res.locals.settings.geocoding_provider || nominatim.DEFAULT_ENDPOINT
},
cache: providerCache,
getParams (req, res) {
const countrycodes = res.locals.settings.geocoding_countrycodes || []
@@ -20,4 +23,6 @@ module.exports = {
}
},
}
}
module.exports = nominatim

View File

@@ -1,10 +1,13 @@
const cache = require('memory-cache')
const providerCache = new cache.Cache()
module.exports = {
const photon = {
commonName: 'Photon',
DEFAULT_ENDPOINT: 'https://photon.komoot.io/api/',
endpoint: (req, res) => {
return res.locals.settings.geocoding_provider || this.DEFAULT_ENDPOINT
return res.locals.settings.geocoding_provider || photon.DEFAULT_ENDPOINT
},
cache: providerCache,
getParams (req, res) {
const details = req.params.place_details
@@ -15,4 +18,6 @@ module.exports = {
}
}
}
}
module.exports = photon