mirror of
https://codeberg.org/slatian/service.echoip-slatecave.git
synced 2025-07-16 05:53:28 +02:00
Updated maxminddb dependency, added location info to lookup
This commit is contained in:
33
src/geoip.rs
33
src/geoip.rs
@ -21,8 +21,8 @@ pub struct NamedLocation {
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize, Default, Copy, Clone)]
|
||||
pub struct LocationCoordinates {
|
||||
latitude: f64,
|
||||
logtitude: f64,
|
||||
lat: f64,
|
||||
lon: f64,
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize, Default, Clone)]
|
||||
@ -34,6 +34,8 @@ pub struct LocationResult {
|
||||
subdivisions: Option<Vec<NamedLocation>>,
|
||||
city: Option<NamedLocation>,
|
||||
|
||||
coordinates: Option<LocationCoordinates>,
|
||||
accuracy: Option<u16>,
|
||||
postal_code: Option<String>,
|
||||
time_zone: Option<String>,
|
||||
}
|
||||
@ -76,7 +78,7 @@ names: &Option<BTreeMap<&str, &str>>,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_city_to_named_location(item: geoip2::model::City, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_city_to_named_location(item: geoip2::city::City, languages: &Vec<&String>) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: None,
|
||||
geoname_id: item.geoname_id,
|
||||
@ -84,7 +86,7 @@ pub fn geoip2_city_to_named_location(item: geoip2::model::City, languages: &Vec<
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_continent_to_named_location(item: geoip2::model::Continent, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_continent_to_named_location(item: geoip2::country::Continent, languages: &Vec<&String>) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -92,7 +94,7 @@ pub fn geoip2_continent_to_named_location(item: geoip2::model::Continent, langua
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_country_to_named_location(item: geoip2::model::Country, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_country_to_named_location(item: geoip2::country::Country, languages: &Vec<&String>) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.iso_code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -100,7 +102,7 @@ pub fn geoip2_country_to_named_location(item: geoip2::model::Country, languages:
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_represented_country_to_named_location(item: geoip2::model::RepresentedCountry, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_represented_country_to_named_location(item: geoip2::country::RepresentedCountry, languages: &Vec<&String>) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.iso_code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -108,7 +110,7 @@ pub fn geoip2_represented_country_to_named_location(item: geoip2::model::Represe
|
||||
}
|
||||
}
|
||||
|
||||
pub fn geoip2_subdivision_to_named_location(item: geoip2::model::Subdivision, languages: &Vec<&String>) -> NamedLocation {
|
||||
pub fn geoip2_subdivision_to_named_location(item: geoip2::city::Subdivision, languages: &Vec<&String>) -> NamedLocation {
|
||||
NamedLocation {
|
||||
iso_code: item.iso_code.map(ToString::to_string),
|
||||
geoname_id: item.geoname_id,
|
||||
@ -169,6 +171,23 @@ impl QueryLocation for MMDBCarrier {
|
||||
},
|
||||
None => None,
|
||||
},
|
||||
coordinates: match &res.location {
|
||||
Some(loc) => {
|
||||
if loc.latitude.is_some() && loc.longitude.is_some() {
|
||||
Some(LocationCoordinates {
|
||||
lat: loc.latitude.unwrap_or(0.0),
|
||||
lon: loc.longitude.unwrap_or(0.0),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
},
|
||||
accuracy: match &res.location {
|
||||
Some(loc) => loc.accuracy_radius,
|
||||
None => None,
|
||||
},
|
||||
postal_code: match res.postal {
|
||||
Some(p) => p.code.map(ToString::to_string),
|
||||
None => None,
|
||||
|
Reference in New Issue
Block a user