updated theming and fixed warnings

This commit is contained in:
2026-03-26 10:35:28 +01:00
parent 85549d41f8
commit 63cc84916e
11 changed files with 119 additions and 115 deletions
+4 -14
View File
@@ -1,18 +1,8 @@
use axum::{
extract::State,
http::HeaderMap,
response::IntoResponse,
Json,
};
use axum::{Json, extract::State, http::HeaderMap, response::IntoResponse};
use std::{fs, sync::Arc};
use tracing::error;
use crate::{
auth::check_auth,
error::AppError,
models::SiteConfig,
AppState,
};
use crate::{AppState, auth::check_auth, error::AppError, models::SiteConfig};
pub async fn get_config(State(state): State<Arc<AppState>>) -> impl IntoResponse {
let config_path = state.data_dir.join("config.json");
@@ -20,7 +10,7 @@ pub async fn get_config(State(state): State<Arc<AppState>>) -> impl IntoResponse
.ok()
.and_then(|c| serde_json::from_str::<SiteConfig>(&c).ok())
.unwrap_or_default();
Json(config)
}
@@ -43,4 +33,4 @@ pub async fn update_config(
})?;
Ok(Json(payload))
}
}
+22 -11
View File
@@ -1,17 +1,17 @@
use axum::{
Json,
extract::{Path, State},
http::{HeaderMap, StatusCode},
response::IntoResponse,
Json,
};
use std::{fs, sync::Arc};
use tracing::{error, info, warn};
use crate::{
AppState,
auth::check_auth,
error::AppError,
models::{CreatePostRequest, PostDetail, PostInfo},
AppState,
};
pub async fn create_post(
@@ -25,8 +25,11 @@ pub async fn create_post(
return Err(AppError::BadRequest("Invalid slug".to_string()));
}
let file_path = state.data_dir.join("posts").join(format!("{}.md", payload.slug));
let file_path = state
.data_dir
.join("posts")
.join(format!("{}.md", payload.slug));
let mut file_content = String::new();
if let Some(ref summary) = payload.summary {
if !summary.trim().is_empty() {
@@ -59,7 +62,7 @@ pub async fn delete_post(
let file_path = state.data_dir.join("posts").join(format!("{}.md", slug));
info!("Attempting to delete post at: {:?}", file_path);
if !file_path.exists() {
warn!("Post not found for deletion: {}", slug);
return Err(AppError::NotFound("Post not found".to_string()));
@@ -99,13 +102,17 @@ pub async fn list_posts(State(state): State<Arc<AppState>>) -> impl IntoResponse
let body = parts[2];
let clean_content = body.replace("#", "").replace("\n", " ");
excerpt = clean_content.chars().take(200).collect::<String>();
if clean_content.len() > 200 { excerpt.push_str("..."); }
if clean_content.len() > 200 {
excerpt.push_str("...");
}
}
}
} else {
let clean_content = content.replace("#", "").replace("\n", " ");
excerpt = clean_content.chars().take(200).collect::<String>();
if clean_content.len() > 200 { excerpt.push_str("..."); }
if clean_content.len() > 200 {
excerpt.push_str("...");
}
}
}
posts.push(PostInfo {
@@ -125,7 +132,7 @@ pub async fn get_post(
Path(slug): Path<String>,
) -> Result<Json<PostDetail>, AppError> {
let file_path = state.data_dir.join("posts").join(format!("{}.md", slug));
match fs::read_to_string(&file_path) {
Ok(raw_content) => {
let mut summary = None;
@@ -145,8 +152,12 @@ pub async fn get_post(
}
}
Ok(Json(PostDetail { slug, summary, content }))
},
Ok(Json(PostDetail {
slug,
summary,
content,
}))
}
Err(_) => Err(AppError::NotFound("Post not found".to_string())),
}
}
}
+15 -8
View File
@@ -1,17 +1,16 @@
use axum::{
Json,
extract::{Multipart, State},
http::HeaderMap,
response::IntoResponse,
Json,
};
use std::{fs, sync::Arc};
use tracing::{error, info, warn};
use crate::{
AppState,
auth::check_auth,
error::AppError,
models::{FileInfo, UploadResponse},
AppState,
};
pub async fn list_uploads(
@@ -57,12 +56,12 @@ pub async fn upload_file(
info!("Processing upload for: {}", file_name);
let slugified_name = slug::slugify(&file_name);
let extension = std::path::Path::new(&file_name)
.extension()
.and_then(|e| e.to_str())
.unwrap_or("");
let final_name = if !extension.is_empty() {
format!("{}.{}", slugified_name, extension)
} else {
@@ -79,7 +78,12 @@ pub async fn upload_file(
file_path
};
let final_name_str = final_path.file_name().unwrap().to_str().unwrap().to_string();
let final_name_str = final_path
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string();
let data = match field.bytes().await {
Ok(bytes) => bytes,
@@ -91,7 +95,10 @@ pub async fn upload_file(
if let Err(e) = fs::write(&final_path, &data) {
error!("Failed to write file to {:?}: {}", final_path, e);
return Err(AppError::Internal("Write error".to_string(), Some(e.to_string())));
return Err(AppError::Internal(
"Write error".to_string(),
Some(e.to_string()),
));
}
info!("File uploaded successfully to {:?}", final_path);
@@ -102,4 +109,4 @@ pub async fn upload_file(
warn!("Upload failed: no file found in multipart stream");
Err(AppError::BadRequest("No file found".to_string()))
}
}