summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2025-11-21 14:09:41 +0100
committerWriterV2 <primary-v2@protonmail.com>2025-11-21 14:09:41 +0100
commit66d7a13414e2b185df5155a83bbdb842d3618c27 (patch)
treef7ae4ea7a8d41c8741e9c296bb38bfccd3cadc52 /src/db
parent3262200e0ca378e433e5f05074416c4b8b83f23c (diff)
Remove story epub
Diffstat (limited to 'src/db')
-rw-r--r--src/db/story.rs28
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" }
}
}
)