This commit is contained in:
parent
6532666c56
commit
ad14135ddf
6 changed files with 177 additions and 78 deletions
|
|
@ -1,12 +1,13 @@
|
|||
use crisp::types::{Keyword, Symbol, Value};
|
||||
use miette::{IntoDiagnostic, Result};
|
||||
use mupdf::{Document, Page};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use sqlx::{
|
||||
pool::PoolConnection, prelude::FromRow, query, sqlite::SqliteRow,
|
||||
Row, Sqlite, SqliteConnection, SqlitePool,
|
||||
};
|
||||
use std::path::PathBuf;
|
||||
use tracing::error;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use tracing::{debug, error};
|
||||
|
||||
use crate::{Background, Slide, SlideBuilder, TextAlignment};
|
||||
|
||||
|
|
@ -27,9 +28,7 @@ pub enum PresKind {
|
|||
Generic,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize,
|
||||
)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Presentation {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
|
|
@ -37,6 +36,17 @@ pub struct Presentation {
|
|||
pub kind: PresKind,
|
||||
}
|
||||
|
||||
impl Eq for Presentation {}
|
||||
|
||||
impl PartialEq for Presentation {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.id == other.id
|
||||
&& self.title == other.title
|
||||
&& self.path == other.path
|
||||
&& self.kind == other.kind
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Presentation> for Value {
|
||||
fn from(value: &Presentation) -> Self {
|
||||
Self::List(vec![Self::Symbol(Symbol("presentation".into()))])
|
||||
|
|
@ -117,22 +127,36 @@ impl ServiceTrait for Presentation {
|
|||
}
|
||||
|
||||
fn to_slides(&self) -> Result<Vec<Slide>> {
|
||||
let slide = SlideBuilder::new()
|
||||
.background(
|
||||
Background::try_from(self.path.clone())
|
||||
.into_diagnostic()?,
|
||||
)
|
||||
.text("")
|
||||
.audio("")
|
||||
.font("")
|
||||
.font_size(50)
|
||||
.text_alignment(TextAlignment::MiddleCenter)
|
||||
.video_loop(false)
|
||||
.video_start_time(0.0)
|
||||
.video_end_time(0.0)
|
||||
.build()?;
|
||||
|
||||
Ok(vec![slide])
|
||||
debug!(?self);
|
||||
let background = Background::try_from(self.path.clone())
|
||||
.into_diagnostic()?;
|
||||
debug!(?background);
|
||||
let doc = Document::open(background.path.as_path())
|
||||
.into_diagnostic()?;
|
||||
debug!(?doc);
|
||||
let pages = doc.page_count().into_diagnostic()?;
|
||||
debug!(?pages);
|
||||
let mut slides: Vec<Slide> = vec![];
|
||||
for page in 0..pages {
|
||||
let slide = SlideBuilder::new()
|
||||
.background(
|
||||
Background::try_from(self.path.clone())
|
||||
.into_diagnostic()?,
|
||||
)
|
||||
.text("")
|
||||
.audio("")
|
||||
.font("")
|
||||
.font_size(50)
|
||||
.text_alignment(TextAlignment::MiddleCenter)
|
||||
.video_loop(false)
|
||||
.video_start_time(0.0)
|
||||
.video_end_time(0.0)
|
||||
.pdf_index(page as u32)
|
||||
.build()?;
|
||||
slides.push(slide);
|
||||
}
|
||||
debug!(?slides);
|
||||
Ok(slides)
|
||||
}
|
||||
|
||||
fn box_clone(&self) -> Box<dyn ServiceTrait> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue