diff --git a/.env.example b/.env.example index 1bc62e5..c401b94 100644 --- a/.env.example +++ b/.env.example @@ -13,3 +13,8 @@ GITHUB_CLIENT_SECRET= # Discord DISCORD_WEBHOOK_URL= + +# Config + +# Globally disables download counting, in the event of abuse +DISABLE_DOWNLOAD_COUNTS=0 \ No newline at end of file diff --git a/src/endpoints/mod_versions.rs b/src/endpoints/mod_versions.rs index acd6061..834ff34 100644 --- a/src/endpoints/mod_versions.rs +++ b/src/endpoints/mod_versions.rs @@ -189,6 +189,13 @@ pub async fn download_version( }; let url = mod_version.download_link; + if data.disable_downloads { + // whatever + return Ok(HttpResponse::Found() + .append_header(("Location", url)) + .finish()); + } + let ip = match info.realip_remote_addr() { None => return Err(ApiError::InternalError), Some(i) => i, diff --git a/src/main.rs b/src/main.rs index c808c91..bdeec61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ pub struct AppData { github_client_id: String, github_client_secret: String, webhook_url: String, + disable_downloads: bool, } #[derive(Debug, Parser)] @@ -65,13 +66,15 @@ async fn main() -> anyhow::Result<()> { let github_client = dotenvy::var("GITHUB_CLIENT_ID").unwrap_or("".to_string()); let github_secret = dotenvy::var("GITHUB_CLIENT_SECRET").unwrap_or("".to_string()); let webhook_url = dotenvy::var("DISCORD_WEBHOOK_URL").unwrap_or("".to_string()); + let disable_downloads = dotenvy::var("DISABLE_DOWNLOAD_COUNTS").unwrap_or("0".to_string()) == "1"; let app_data = AppData { db: pool.clone(), app_url: app_url.clone(), github_client_id: github_client.clone(), github_client_secret: github_secret.clone(), - webhook_url: webhook_url.clone() + webhook_url: webhook_url.clone(), + disable_downloads, }; let args = Args::parse();