Final V2 Changes (#212)

* Redo dependencies, add rejection reasons, make notifications more readable

* Fix errors, add dependency route, finish PR

* Fix clippy errors
This commit is contained in:
Geometrically
2021-06-16 09:05:35 -07:00
committed by GitHub
parent 2a4caa856e
commit d2c2503cfa
39 changed files with 2365 additions and 1303 deletions

View File

@@ -11,13 +11,13 @@ use search::indexing::index_projects;
use search::indexing::IndexingSettings;
use std::sync::Arc;
mod auth;
mod database;
mod file_hosting;
mod models;
mod routes;
mod scheduler;
mod search;
mod util;
mod validate;
#[derive(Debug, Options)]
@@ -265,9 +265,23 @@ async fn main() -> std::io::Result<()> {
.with_identifier(|req| {
let connection_info = req.connection_info();
let ip = String::from(
connection_info
.remote_addr()
.ok_or(ARError::IdentificationError)?,
if dotenv::var("CLOUDFLARE_INTEGRATION")
.ok()
.map(|i| i.parse().unwrap())
.unwrap_or(false)
{
if let Some(header) = req.headers().get("CF-Connecting-IP") {
header.to_str().map_err(|_| ARError::IdentificationError)?
} else {
connection_info
.remote_addr()
.ok_or(ARError::IdentificationError)?
}
} else {
connection_info
.remote_addr()
.ok_or(ARError::IdentificationError)?
},
);
let ignore_ips = dotenv::var("RATE_LIMIT_IGNORE_IPS")
@@ -277,16 +291,16 @@ async fn main() -> std::io::Result<()> {
if ignore_ips.contains(&ip) {
// At an even distribution of numbers, this will allow at the most
// 3000 requests per minute from the frontend, which is reasonable
// (50 requests per second)
let random = rand::thread_rng().gen_range(1, 15);
// 18000 requests per minute from the frontend, which is reasonable
// (300 requests per second)
let random = rand::thread_rng().gen_range(1, 30);
return Ok(format!("{}-{}", ip, random));
}
Ok(ip)
})
.with_interval(std::time::Duration::from_secs(60))
.with_max_requests(200),
.with_max_requests(300),
)
.wrap(sentry_actix::Sentry::new())
.data(pool.clone())
@@ -335,6 +349,7 @@ fn check_env_vars() -> bool {
failed |= true;
}
failed |= check_var::<String>("SITE_URL");
failed |= check_var::<String>("CDN_URL");
failed |= check_var::<String>("DATABASE_URL");
failed |= check_var::<String>("MEILISEARCH_ADDR");