summaryrefslogtreecommitdiff
path: root/src/handlers/admin.rs
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2024-11-05 19:06:54 +0100
committerWriterV2 <primary-v2@protonmail.com>2024-11-05 19:06:54 +0100
commit845073129204835413b53bb40ca7b6a7806d373a (patch)
tree32b62478e3cee43eae9472a0ad69e8890e30b6e6 /src/handlers/admin.rs
parentdab09c4e4d1e4b21216b630bb44e57f597dfe85b (diff)
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/
Diffstat (limited to 'src/handlers/admin.rs')
-rw-r--r--src/handlers/admin.rs14
1 files changed, 5 insertions, 9 deletions
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 {