diff options
author | Hygna <hygna@proton.me> | 2022-10-29 12:46:53 +0100 |
---|---|---|
committer | Hygna <hygna@proton.me> | 2022-10-29 12:46:53 +0100 |
commit | 73cc5ce38d42593011f5d0bf5ffb82827cc6adfe (patch) | |
tree | 39d2684ce3e5334c64ffaddf7481ba8ff08ceeba /src/assets | |
parent | Added PrivateBin (diff) | |
download | libredirect-73cc5ce38d42593011f5d0bf5ffb82827cc6adfe.zip |
Changes:
Added note about Privacy Redirect Disabled maps redirects by default due to bugs Added timeout to osm web request Closes https://github.com/libredirect/libredirect/issues/485
Diffstat (limited to 'src/assets')
-rw-r--r-- | src/assets/javascripts/services.js | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 1e50b43d..432420fb 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -183,16 +183,25 @@ function redirect(url, type, initiator, forceRedirection) { function addressToLatLng(address) { const xmlhttp = new XMLHttpRequest() - xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false) + xmlhttp.timeout = 5000 + http.ontimeout = () => { + return + } + http.onerror = () => { + return + } xmlhttp.send() - if (xmlhttp.status === 200) { - const json = JSON.parse(xmlhttp.responseText)[0] - if (json) { - console.log("json", json) - return [`${json.lat},${json.lon}`, `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`] + http.onreadystatechange = () => { + if (xmlhttp.status === 200) { + const json = JSON.parse(xmlhttp.responseText)[0] + if (json) { + console.log("json", json) + return [`${json.lat},${json.lon}`, `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`] + } } + console.info("Error: Status is " + xmlhttp.status) } - console.info("Error: Status is " + xmlhttp.status) + xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false) } let mapCentre = "#" |