diff options
Diffstat (limited to 'src/db')
| -rw-r--r-- | src/db/story.rs | 28 |
1 files changed, 7 insertions, 21 deletions
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<u8>, - pub epub: Vec<u8>, 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<T: PageBuilder<'a> + ProductMarker>( &self, specific_product: &super::product::SpecificProduct<T>, @@ -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" } } } ) |
