feat: update dependencies, enhance upload rate limiting, and improve UI elements
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -14,6 +14,9 @@ use std::{env, fs, path::PathBuf, sync::LazyLock};
|
||||
pub static HTML_DIR: &str = "data/html/";
|
||||
pub static LOG_DIR: &str = "data/logs/";
|
||||
pub static LOG_FILE_NAME: &str = "log.txt";
|
||||
pub static MAX_ASSETS: usize = 1000;
|
||||
pub static MAX_ASSET_SIZE_BYTES: usize = 3 * 1024 * 1024; // 3 MB
|
||||
pub static MAX_UPLOADS_PER_HOUR_PER_USER: usize = 10;
|
||||
|
||||
pub static BIND_ADDR: LazyLock<String> = LazyLock::new(|| match env::var("BIND_ADDR") {
|
||||
Ok(addr) => {
|
||||
@@ -71,6 +74,7 @@ async fn view_asset(req: HttpRequest) -> actix_web::Result<NamedFile> {
|
||||
|
||||
#[route("/{tail:.*}", method = "GET", method = "POST")]
|
||||
async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> actix_web::Result<NamedFile> {
|
||||
println!("Catch-all route triggered for path: {}", req.uri().path());
|
||||
let response = match req.uri().path() {
|
||||
path if STATIC_PAGES.contains(&path[1..].into()) => {
|
||||
let file_path = HTML_DIR.to_string() + path;
|
||||
@@ -108,24 +112,24 @@ async fn main() -> std::io::Result<()> {
|
||||
});
|
||||
println!("Rotated log file to: {}_{}", time_tag, &LOG_FILE_NAME);
|
||||
}
|
||||
let assets = data_mgt::AssetTracker::new();
|
||||
let app_state = data_mgt::AppState::default();
|
||||
|
||||
println!("Starting server at http://{}:{}/", *BIND_ADDR, *BIND_PORT);
|
||||
let assets_clone = assets.clone();
|
||||
|
||||
let inner_appt_state = app_state.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(1));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if let Err(e) = data_mgt::clear_assets(assets_clone.clone()).await {
|
||||
if let Err(e) = data_mgt::clear_app_data(&inner_appt_state).await {
|
||||
eprintln!("Error clearing assets: {}", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.app_data(web::JsonConfig::default().limit(1024 * 1024 * 3))
|
||||
.app_data(web::Data::new(assets.clone()))
|
||||
.app_data(web::JsonConfig::default().limit(1024 * 1024 * 3)) // 3MB limit
|
||||
.app_data(web::Data::new(app_state.clone()))
|
||||
.service(index)
|
||||
.service(stats)
|
||||
.service(view_asset)
|
||||
|
||||
Reference in New Issue
Block a user