global: snapshot

This commit is contained in:
nym21
2025-04-03 14:31:39 +02:00
parent 4c2da31bb3
commit e8c34dd59b
51 changed files with 2561 additions and 5501 deletions
+6 -16
View File
@@ -1,15 +1,15 @@
use std::{fs, path::Path, time::Instant};
use std::{fs, path::Path};
use axum::{
body::Body,
extract::{self, State},
http::{HeaderMap, StatusCode, Uri},
http::{HeaderMap, StatusCode},
response::{IntoResponse, Response},
};
use log::{error, info};
use crate::{
AppState, log_result,
AppState,
traits::{HeaderMapExtended, ModifiedState, ResponseExtended},
};
@@ -18,24 +18,18 @@ use super::minify::minify_js;
pub async fn file_handler(
headers: HeaderMap,
State(app_state): State<AppState>,
uri: Uri,
path: extract::Path<String>,
) -> Response {
any_handler(headers, app_state, uri, Some(path))
any_handler(headers, app_state, Some(path))
}
pub async fn index_handler(
headers: HeaderMap,
State(app_state): State<AppState>,
uri: Uri,
) -> Response {
any_handler(headers, app_state, uri, None)
pub async fn index_handler(headers: HeaderMap, State(app_state): State<AppState>) -> Response {
any_handler(headers, app_state, None)
}
fn any_handler(
headers: HeaderMap,
app_state: AppState,
uri: Uri,
path: Option<extract::Path<String>>,
) -> Response {
let website_path = app_state
@@ -44,8 +38,6 @@ fn any_handler(
.expect("Should never reach here is websites_path is None")
.join(app_state.website.to_folder_name());
let instant = Instant::now();
let response = if let Some(path) = path.as_ref() {
let path = path.0.replace("..", "").replace("\\", "");
@@ -72,8 +64,6 @@ fn any_handler(
path_to_response(&headers, &website_path.join("index.html"))
};
log_result(response.status(), &uri, instant);
response
}