feat: enhance upload handling and logging improvements
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
use actix_web::http::header;
|
||||
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
||||
use base64::{Engine, engine::general_purpose};
|
||||
|
||||
|
||||
@@ -111,8 +111,7 @@ impl AssetStorage {
|
||||
}
|
||||
|
||||
pub async fn add_asset(&self, asset: Asset) {
|
||||
print!("[{}] Adding asset: {}", chrono::Local::now().to_rfc3339(), asset.id());
|
||||
|
||||
println!("[{}] Adding asset: {}", chrono::Local::now().to_rfc3339(), asset.id());
|
||||
self.assets.lock().await.push(asset);
|
||||
self.show_assets().await;
|
||||
}
|
||||
@@ -156,7 +155,8 @@ impl AssetStorage {
|
||||
pub async fn show_assets(&self) {
|
||||
for asset in self.assets.lock().await.iter() {
|
||||
println!(
|
||||
"Asset ID: {}, Expires At: {}, MIME: {}, Size: {} bytes",
|
||||
"[{}] Asset ID: {}, Expires At: {}, Mime: {}, Size: {} bytes",
|
||||
chrono::Local::now().to_rfc3339(),
|
||||
asset.id(),
|
||||
asset.expires_at(),
|
||||
asset.mime(),
|
||||
@@ -192,11 +192,15 @@ impl RateLimiter {
|
||||
entry.push(asset_exp_time);
|
||||
(true, None)
|
||||
} else {
|
||||
println!(
|
||||
"[{}] Rate limit exceeded for IP: {}",
|
||||
chrono::Local::now().to_rfc3339(),
|
||||
client_ip
|
||||
);
|
||||
let first_to_expire = entry.iter().min().copied().unwrap();
|
||||
let retry_after_ms = (first_to_expire - now).max(1);
|
||||
(false, Some(retry_after_ms))
|
||||
};
|
||||
println!("{:?}", clients);
|
||||
ret_val
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,6 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user