You've already forked AstralRinth
forked from didirus/AstralRinth
Fix MaxMind (#4590)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use std::{
|
||||
io::{Cursor, Read},
|
||||
net::IpAddr,
|
||||
path::Path,
|
||||
sync::Arc,
|
||||
};
|
||||
@@ -49,6 +50,19 @@ impl MaxMind {
|
||||
.ok(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Queries the MaxMind database for the ISO country code of an IP address.
|
||||
///
|
||||
/// If MaxMind is not configured or the database could not be read, returns
|
||||
/// [`None`].
|
||||
pub async fn query_country(&self, ip: impl Into<IpAddr>) -> Option<String> {
|
||||
let reader = self.reader.as_ref()?;
|
||||
reader
|
||||
.lookup::<geoip2::Country>(ip.into())
|
||||
.ok()?
|
||||
.and_then(|c| c.country)
|
||||
.and_then(|c| c.iso_code.map(|s| s.to_string()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a [`maxminddb::Reader`] for use in [`MaxMind::reader`].
|
||||
|
||||
Reference in New Issue
Block a user