fix: enhance logging structure by adding missing log event types and improving error handling in API

This commit is contained in:
2026-01-11 08:46:14 +01:00
parent 2ef2b827b7
commit 7d02443e67
3 changed files with 68 additions and 46 deletions

View File

@@ -6,7 +6,7 @@ use serde_json::json;
use crate::{
data_mgt::AssetTracker,
logs::{LogEventType, log_event},
logs::{LogEventBody, LogEventLine, LogEventType, log_event},
};
#[derive(Deserialize, Debug)]
@@ -24,10 +24,12 @@ async fn api_upload(
) -> Result<HttpResponse, actix_web::Error> {
// Convert to bytes
let content_bytes = if body.content_type == "text/plain" {
body.content.as_bytes().to_vec() // UTF-8 bytes
body.content.as_bytes().to_vec()
} else {
// Decode base64 → bytes
general_purpose::STANDARD.decode(&body.content).unwrap()
match general_purpose::STANDARD.decode(&body.content) {
Ok(bytes) => bytes,
Err(_) => return Ok(HttpResponse::BadRequest().body("Invalid base64 payload")),
}
};
let connection_info = req.connection_info();
let uploader_ip = connection_info
@@ -86,40 +88,6 @@ struct ActivityItem {
timestamp: String,
}
#[derive(Deserialize)]
struct LogEventLine {
time: String,
event: LogEventBody,
}
#[derive(Deserialize)]
enum LogEventBody {
AssetUploaded(LogAsset),
AssetDeleted(LogAsset),
HttpRequest(LogHttpRequest),
}
#[derive(Deserialize)]
struct LogAsset {
id: String,
share_duration: u32,
created_at: i64,
expires_at: i64,
mime: String,
uploader_ip: Option<String>,
}
#[derive(Deserialize)]
struct LogHttpRequest {
method: String,
path: String,
query_string: String,
scheme: String,
ip: String,
real_ip: String,
user_agent: String,
}
#[get("/api/stats")]
async fn api_stats(assets: web::Data<AssetTracker>) -> Result<HttpResponse, actix_web::Error> {
use crate::LOG_DIR;