mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-09-24 10:20:50 +02:00
fix: update maxminddb usage
This commit is contained in:
Vendored
+1
@@ -103,6 +103,7 @@
|
|||||||
"lzma",
|
"lzma",
|
||||||
"macchiato",
|
"macchiato",
|
||||||
"Matchalk",
|
"Matchalk",
|
||||||
|
"maxminddb",
|
||||||
"minioadmin",
|
"minioadmin",
|
||||||
"mmdb",
|
"mmdb",
|
||||||
"mountpoint",
|
"mountpoint",
|
||||||
|
|||||||
@@ -343,14 +343,16 @@ pub fn get_geolocation(ip: &str) -> Result<Geolocation, GeolocationError> {
|
|||||||
let ip_addr: IpAddr =
|
let ip_addr: IpAddr =
|
||||||
IpAddr::from_str(ip).map_err(|_| GeolocationError::InvalidIP(ip.to_string()))?;
|
IpAddr::from_str(ip).map_err(|_| GeolocationError::InvalidIP(ip.to_string()))?;
|
||||||
|
|
||||||
let city: geoip2::City = reader
|
let lookup_result = reader
|
||||||
.lookup(ip_addr)
|
.lookup(ip_addr)
|
||||||
.map_err(|e| GeolocationError::LocationNotFound(e.to_string()))?;
|
.map_err(|e| GeolocationError::LocationNotFound(e.to_string()))?;
|
||||||
|
let city: geoip2::City = lookup_result
|
||||||
|
.decode()
|
||||||
|
.map_err(|e| GeolocationError::LocationNotFound(e.to_string()))?
|
||||||
|
.ok_or_else(|| GeolocationError::LocationNotFound(ip.to_string()))?;
|
||||||
|
|
||||||
// Extract location data
|
// Extract location data
|
||||||
let location = city
|
let location = &city.location;
|
||||||
.location
|
|
||||||
.ok_or_else(|| GeolocationError::LocationNotFound(ip.to_string()))?;
|
|
||||||
|
|
||||||
let longitude = location
|
let longitude = location
|
||||||
.longitude
|
.longitude
|
||||||
@@ -364,9 +366,7 @@ pub fn get_geolocation(ip: &str) -> Result<Geolocation, GeolocationError> {
|
|||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
// Get country code
|
// Get country code
|
||||||
let country = city
|
let country = &city.country;
|
||||||
.country
|
|
||||||
.ok_or_else(|| GeolocationError::LocationNotFound("No country".to_string()))?;
|
|
||||||
let iso_code = country
|
let iso_code = country
|
||||||
.iso_code
|
.iso_code
|
||||||
.ok_or_else(|| GeolocationError::LocationNotFound("No country code".to_string()))?
|
.ok_or_else(|| GeolocationError::LocationNotFound("No country code".to_string()))?
|
||||||
|
|||||||
Reference in New Issue
Block a user