From 845073129204835413b53bb40ca7b6a7806d373a Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Tue, 5 Nov 2024 19:06:54 +0100 Subject: Feat: Add card content for story - Refactoring: Add filepath formatting method - Add extra error context in story file sync - Add specific product as parameter to product specific card content trait method - TODO: Add pdf icon and epub icon to story card content - Update tailwind config to look in all .rs files in src/ --- src/handlers/admin.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'src/handlers/admin.rs') diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index 6cfe133..a48be21 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -11,7 +11,7 @@ use axum::{Extension, Json}; use rand::Rng; use subtle::ConstantTimeEq; -use crate::db::story::Story; +use crate::db::story::{format_filepath, Story}; use crate::db::ProductDatabaseHandler; use crate::error::AppError; @@ -95,10 +95,8 @@ pub async fn upload_story( }; let pdf = if let Some(pdf_value) = form.get("pdf") { - let mut filename = format!("{}.pdf", name).to_lowercase(); - filename.retain(|c| !c.is_whitespace()); - - let file = std::fs::File::create_new(format!("static/{}", filename))?; + let filename = format_filepath(&name, "pdf"); + let file = std::fs::File::create_new(filename)?; BufWriter::new(file).write_all(pdf_value)?; pdf_value.to_vec() } else { @@ -106,10 +104,8 @@ pub async fn upload_story( }; let epub = if let Some(epub_value) = form.get("epub") { - let mut filename = format!("{}.epub", name).to_lowercase(); - filename.retain(|c| !c.is_whitespace()); - - let file = std::fs::File::create_new(format!("static/{}", filename))?; + let filename = format_filepath(&name, "epub"); + let file = std::fs::File::create_new(filename)?; BufWriter::new(file).write_all(epub_value)?; epub_value.to_vec() } else { -- cgit v1.2.3