Fix clippy error (?)

This commit is contained in:
Geometrically
2021-01-01 09:13:27 -07:00
parent ee8d65977d
commit a40b9f4054
2 changed files with 20 additions and 15 deletions

View File

@@ -1,15 +1,15 @@
use crate::file_hosting::S3Host; use crate::file_hosting::S3Host;
use actix_cors::Cors; use actix_cors::Cors;
use actix_ratelimit::errors::ARError;
use actix_ratelimit::{MemoryStore, MemoryStoreActor, RateLimiter}; use actix_ratelimit::{MemoryStore, MemoryStoreActor, RateLimiter};
use actix_web::{http, web, App, HttpServer}; use actix_web::{http, web, App, HttpServer};
use env_logger::Env; use env_logger::Env;
use gumdrop::Options; use gumdrop::Options;
use log::{error, info, warn}; use log::{error, info, warn};
use rand::Rng;
use search::indexing::index_mods; use search::indexing::index_mods;
use search::indexing::IndexingSettings; use search::indexing::IndexingSettings;
use std::sync::Arc; use std::sync::Arc;
use actix_ratelimit::errors::ARError;
use rand::Rng;
mod auth; mod auth;
mod database; mod database;
@@ -243,13 +243,15 @@ async fn main() -> std::io::Result<()> {
// Init App // Init App
HttpServer::new(move || { HttpServer::new(move || {
App::new() App::new()
.wrap(Cors::new() .wrap(
.allowed_methods(vec!["GET", "POST", "DELETE", "PATCH", "PUT"]) Cors::new()
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT]) .allowed_methods(vec!["GET", "POST", "DELETE", "PATCH", "PUT"])
.allowed_header(http::header::CONTENT_TYPE) .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
.send_wildcard() .allowed_header(http::header::CONTENT_TYPE)
.max_age(3600) .send_wildcard()
.finish()) .max_age(3600)
.finish(),
)
.wrap( .wrap(
// This is a hacky workaround to allowing the frontend server-side renderer to have // This is a hacky workaround to allowing the frontend server-side renderer to have
// an unlimited rate limit, since there is no current way with this library to // an unlimited rate limit, since there is no current way with this library to
@@ -257,21 +259,23 @@ async fn main() -> std::io::Result<()> {
RateLimiter::new(MemoryStoreActor::from(store.clone()).start()) RateLimiter::new(MemoryStoreActor::from(store.clone()).start())
.with_identifier(|req| { .with_identifier(|req| {
let connection_info = req.connection_info(); let connection_info = req.connection_info();
let ip = String::from(connection_info let ip = String::from(
.remote_addr() connection_info
.ok_or(ARError::IdentificationError)?); .remote_addr()
.ok_or(ARError::IdentificationError)?,
);
let ignore_ips = dotenv::var("RATE_LIMIT_IGNORE_IPS") let ignore_ips = dotenv::var("RATE_LIMIT_IGNORE_IPS")
.ok() .ok()
.and_then(|s| serde_json::from_str::<Vec<String>>(&s).ok()) .and_then(|s| serde_json::from_str::<Vec<String>>(&s).ok())
.unwrap_or(vec![]); .unwrap_or_else(Vec::new);
if ignore_ips.contains(&ip) { if ignore_ips.contains(&ip) {
// At an even distribution of numbers, this will allow at the most // At an even distribution of numbers, this will allow at the most
// 3000 requests per minute from the frontend, which is reasonable // 3000 requests per minute from the frontend, which is reasonable
// (50 requests per second) // (50 requests per second)
let random = rand::thread_rng().gen_range(1, 15); let random = rand::thread_rng().gen_range(1, 15);
return Ok(format!("{}-{}", ip, random)) return Ok(format!("{}-{}", ip, random));
} }
Ok(ip) Ok(ip)

View File

@@ -8,6 +8,7 @@ use actix_web::{delete, get, patch, web, HttpRequest, HttpResponse};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sqlx::PgPool; use sqlx::PgPool;
use std::sync::Arc; use std::sync::Arc;
use std::borrow::Borrow;
// TODO: this needs filtering, and a better response type // TODO: this needs filtering, and a better response type
// Currently it only gives a list of ids, which have to be // Currently it only gives a list of ids, which have to be
@@ -659,7 +660,7 @@ pub async fn download_version(
if let Some(id) = result { if let Some(id) = result {
let real_ip = req.connection_info(); let real_ip = req.connection_info();
let ip_option = real_ip.realip_remote_addr(); let ip_option = real_ip.borrow().remote_addr();
if let Some(ip) = ip_option { if let Some(ip) = ip_option {
let hash = sha1::Sha1::from(format!("{}{}", ip, pepper.pepper)).hexdigest(); let hash = sha1::Sha1::from(format!("{}{}", ip, pepper.pepper)).hexdigest();