Skip to content

Commit

Permalink
so we don't have to turn off the servers
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Sep 4, 2024
1 parent 4910058 commit 757220f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions src/endpoints/mod_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct AppData {
github_client_id: String,
github_client_secret: String,
webhook_url: String,
disable_downloads: bool,
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 757220f

Please sign in to comment.