updated theming and fixed warnings
This commit is contained in:
@@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user