Skip to content

Commit 757220f

Browse files
committed
so we don't have to turn off the servers
1 parent 4910058 commit 757220f

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ GITHUB_CLIENT_SECRET=
1313
# Discord
1414

1515
DISCORD_WEBHOOK_URL=
16+
17+
# Config
18+
19+
# Globally disables download counting, in the event of abuse
20+
DISABLE_DOWNLOAD_COUNTS=0

src/endpoints/mod_versions.rs

+7
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ pub async fn download_version(
189189
};
190190
let url = mod_version.download_link;
191191

192+
if data.disable_downloads {
193+
// whatever
194+
return Ok(HttpResponse::Found()
195+
.append_header(("Location", url))
196+
.finish());
197+
}
198+
192199
let ip = match info.realip_remote_addr() {
193200
None => return Err(ApiError::InternalError),
194201
Some(i) => i,

src/main.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub struct AppData {
2626
github_client_id: String,
2727
github_client_secret: String,
2828
webhook_url: String,
29+
disable_downloads: bool,
2930
}
3031

3132
#[derive(Debug, Parser)]
@@ -65,13 +66,15 @@ async fn main() -> anyhow::Result<()> {
6566
let github_client = dotenvy::var("GITHUB_CLIENT_ID").unwrap_or("".to_string());
6667
let github_secret = dotenvy::var("GITHUB_CLIENT_SECRET").unwrap_or("".to_string());
6768
let webhook_url = dotenvy::var("DISCORD_WEBHOOK_URL").unwrap_or("".to_string());
69+
let disable_downloads = dotenvy::var("DISABLE_DOWNLOAD_COUNTS").unwrap_or("0".to_string()) == "1";
6870

6971
let app_data = AppData {
7072
db: pool.clone(),
7173
app_url: app_url.clone(),
7274
github_client_id: github_client.clone(),
7375
github_client_secret: github_secret.clone(),
74-
webhook_url: webhook_url.clone()
76+
webhook_url: webhook_url.clone(),
77+
disable_downloads,
7578
};
7679

7780
let args = Args::parse();

0 commit comments

Comments
 (0)