Replace MaxMind with CloudFlare headers (#4934)

* Replace MaxMind with CloudFlare headers

* Remove MaxMind env vars

* Fix test harness
This commit is contained in:
aecsocket
2025-12-30 16:49:49 +00:00
committed by GitHub
parent b07a1659b4
commit ad3edf541b
11 changed files with 16 additions and 30 deletions

View File

@@ -9,7 +9,6 @@ use crate::util::date::get_current_tenths_of_ms;
use crate::util::env::parse_strings_from_var;
use actix_web::{HttpRequest, HttpResponse};
use actix_web::{post, web};
use modrinth_maxmind::MaxMind;
use serde::Deserialize;
use sqlx::PgPool;
use std::collections::HashMap;
@@ -49,7 +48,6 @@ pub struct UrlInput {
#[post("view")]
pub async fn page_view_ingest(
req: HttpRequest,
maxmind: web::Data<MaxMind>,
analytics_queue: web::Data<Arc<AnalyticsQueue>>,
session_queue: web::Data<AuthQueue>,
url_input: web::Json<UrlInput>,
@@ -114,7 +112,7 @@ pub async fn page_view_ingest(
user_id: 0,
project_id: 0,
ip,
country: maxmind.query_country(ip).await.unwrap_or_default(),
country: headers.get("cf-ipcountry").cloned().unwrap_or_default(),
user_agent: headers.get("user-agent").cloned().unwrap_or_default(),
headers: headers
.into_iter()

View File

@@ -10,7 +10,6 @@ use crate::search::SearchConfig;
use crate::util::date::get_current_tenths_of_ms;
use crate::util::guards::admin_key_guard;
use actix_web::{HttpRequest, HttpResponse, patch, post, web};
use modrinth_maxmind::MaxMind;
use serde::Deserialize;
use sqlx::PgPool;
use std::collections::HashMap;
@@ -42,7 +41,6 @@ pub async fn count_download(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
maxmind: web::Data<MaxMind>,
analytics_queue: web::Data<Arc<AnalyticsQueue>>,
session_queue: web::Data<AuthQueue>,
download_body: web::Json<DownloadBody>,
@@ -126,7 +124,11 @@ pub async fn count_download(
project_id: project_id as u64,
version_id: version_id as u64,
ip,
country: maxmind.query_country(ip).await.unwrap_or_default(),
country: download_body
.headers
.get("cf-ipcountry")
.cloned()
.unwrap_or_default(),
user_agent: download_body
.headers
.get("user-agent")