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 +++++--------- src/handlers/frontend_builder.rs | 7 +++++-- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/handlers') 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 { diff --git a/src/handlers/frontend_builder.rs b/src/handlers/frontend_builder.rs index 4a9ea67..515277e 100644 --- a/src/handlers/frontend_builder.rs +++ b/src/handlers/frontend_builder.rs @@ -75,7 +75,7 @@ fn card(specific_product: SpecificProduct) -> (specific_product.product.description) } div { - (specific_product.detail.product_specific_card_content()) + (specific_product.detail.product_specific_card_content(&specific_product)) } div class="flex flex-row space-x-5 mt-9 text-xs" { span {"Upload: " (upload_date)} @@ -114,5 +114,8 @@ pub async fn build_page String; - fn product_specific_card_content(&self) -> Markup; + fn product_specific_card_content( + &self, + specific_product: &SpecificProduct, + ) -> Markup; } -- cgit v1.2.3