From 66d7a13414e2b185df5155a83bbdb842d3618c27 Mon Sep 17 00:00:00 2001 From: WriterV2 Date: Fri, 21 Nov 2025 14:09:41 +0100 Subject: Remove story epub --- src/db/story.rs | 28 +++++++--------------------- src/handlers/admin.rs | 10 ---------- 2 files changed, 7 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/db/story.rs b/src/db/story.rs index 5803351..1566d22 100644 --- a/src/db/story.rs +++ b/src/db/story.rs @@ -19,7 +19,6 @@ pub struct Story { pub id: i64, pub language: String, pub pdf: Vec, - pub epub: Vec, pub pid: i64, } @@ -32,18 +31,14 @@ impl ProductMarker for Story { pub async fn synchronize_story_files(pool: &SqlitePool) -> Result<(), anyhow::Error> { for entry in read_dir("static").with_context(|| "Failed to read directory")? { let path = entry.with_context(|| "Failed to get entry")?.path(); - if path - .extension() - .is_some_and(|ext| ext == OsStr::new("pdf") || ext == OsStr::new("epub")) - { + if path.extension().is_some_and(|ext| ext == OsStr::new("pdf")) { remove_file(path).with_context(|| "Failed to remove file")?; } } - let results = sqlx::query!( - "SELECT p.name, s.pdf, s.epub FROM story s INNER JOIN product p ON s.pid = p.id" - ) - .fetch_all(pool) - .await?; + let results = + sqlx::query!("SELECT p.name, s.pdf FROM story s INNER JOIN product p ON s.pid = p.id") + .fetch_all(pool) + .await?; for result in results.iter() { let pdf_filename = format_filepath(&result.name, "pdf"); let file = std::fs::File::create_new(&pdf_filename) @@ -51,13 +46,6 @@ pub async fn synchronize_story_files(pool: &SqlitePool) -> Result<(), anyhow::Er BufWriter::new(file) .write_all(&result.pdf.to_vec()) .with_context(|| format!("Failed to write {}", &pdf_filename))?; - - let epub_filename = format_filepath(&result.name, "epub"); - let file = std::fs::File::create_new(&epub_filename) - .with_context(|| format!("Failed to create {}", &epub_filename))?; - BufWriter::new(file) - .write_all(&result.epub.to_vec()) - .with_context(|| format!("Failed to write {}", &epub_filename))?; } Ok(()) } @@ -87,10 +75,9 @@ impl ProductDatabaseHandler for Story { let product = Product::post(&mut tx, name, description, tags).await?; let story = sqlx::query_as!( Story, - "INSERT INTO story (language, pdf, epub, pid) VALUES ($1, $2, $3, $4) RETURNING id, language, pdf, epub, pid", + "INSERT INTO story (language, pdf, pid) VALUES ($1, $2, $3) RETURNING id, language, pdf, pid", self.language, self.pdf, - self.epub, product.id) .fetch_one(&mut *tx) .await?; @@ -119,7 +106,7 @@ impl<'a> PageBuilder<'a> for Story { "Stories" } - // TODO: Add pdf and epub icons + // TODO: Add pdf icon fn product_specific_card_content + ProductMarker>( &self, specific_product: &super::product::SpecificProduct, @@ -129,7 +116,6 @@ impl<'a> PageBuilder<'a> for Story { span class="mr-10" { (&self.language) } div class="flex justify-between" { a href=(format_filepath(&specific_product.product.name, "pdf")) { "PDF" } - a href=(format_filepath(&specific_product.product.name, "epub")) { "EPUB" } } } ) diff --git a/src/handlers/admin.rs b/src/handlers/admin.rs index 6cc79c2..1cc3068 100644 --- a/src/handlers/admin.rs +++ b/src/handlers/admin.rs @@ -102,15 +102,6 @@ pub async fn upload_story( return Ok(StatusCode::BAD_REQUEST.into_response()); }; - let epub = if let Some(epub_value) = form.get("epub") { - 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 { - return Ok(StatusCode::BAD_REQUEST.into_response()); - }; - let mut tags: Vec<&str> = Vec::new(); if let Some(tags_value) = form.get("tag") { let tagstring = std::str::from_utf8(tags_value)?; @@ -124,7 +115,6 @@ pub async fn upload_story( pid: 0, language, pdf, - epub, }; let story = story_template -- cgit v1.2.3