feat: add statistics API and dashboard for asset metrics
All checks were successful
Rust CI / build-test (push) Successful in 1m22s

- Implemented `/api/stats` endpoint to return JSON metrics including active assets, total uploads, storage usage, and recent activity.
- Created `stats.html` page to display real-time statistics with auto-refresh functionality.
- Enhanced asset logging to include uploader IP and detailed event information for uploads and deletions.
- Updated asset model to store uploader IP for audit purposes.
- Improved logging functionality to ensure log directory exists before writing.
- Refactored asset creation and management to support new features and logging.
This commit is contained in:
2026-01-09 20:59:24 +01:00
parent 954a5be8cb
commit d6c465466a
10 changed files with 1036 additions and 305 deletions

View File

@@ -10,9 +10,9 @@ use actix_web::{
use serde_json::Value;
use std::{env, fs, path::PathBuf, sync::LazyLock};
pub static HTML_DIR: &str = "html/";
pub static LOG_DIR: &str = "logs/";
pub static DATA_STORAGE: &str = "storage/";
pub static HTML_DIR: &str = "data/html/";
pub static LOG_DIR: &str = "data/logs/";
pub static DATA_STORAGE: &str = "data/storage/";
pub static BIND_ADDR: LazyLock<String> = LazyLock::new(|| match env::var("BIND_ADDR") {
Ok(addr) => {
@@ -43,7 +43,7 @@ pub static STATIC_PAGES: LazyLock<Vec<String>> = LazyLock::new(|| {
});
use crate::{
api::{api_get_asset, api_upload},
api::{api_get_asset, api_stats, api_upload},
logs::log_to_file,
};
@@ -102,6 +102,7 @@ async fn main() -> std::io::Result<()> {
.service(view_asset)
.service(api_get_asset)
.service(api_upload)
.service(api_stats)
.service(catch_all)
})
.bind((BIND_ADDR.clone(), *BIND_PORT))?