Skip to content

Commit

Permalink
⬆️ Upgrade/pin pdf dep to fix panic
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronleopold committed Nov 25, 2023
1 parent a1341e3 commit 28f78a6
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 20 deletions.
112 changes: 94 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ zip = "0.5.13"
epub = "1.2.4"
unrar = { git = "https://github.com/stumpapp/unrar.rs", branch = "feature/typestate" }
# unrar = { version = "0.5.1" }
pdf = "0.8.1"
# pdf = "0.8.1"
pdf = { git = "https://github.com/pdf-rs/pdf", rev = "3bc9e636d31b1846e51b58c7429914e640866f53" } # TODO: revert back to crates.io once fix(es) release
pdfium-render = "0.8.9"
data-encoding = "2.4.0"
ring = "0.16.20"
Expand Down
37 changes: 36 additions & 1 deletion core/src/db/entity/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::collections::HashMap;

use pdf::primitive::Dictionary;
use pdf::{
object::InfoDict,
primitive::{Dictionary, PdfString},
};
use regex::Regex;
use serde::{Deserialize, Deserializer, Serialize};
use specta::Type;
Expand Down Expand Up @@ -442,6 +445,38 @@ impl From<Dictionary> for MediaMetadata {
}
}

fn pdf_string_to_string(pdf_string: PdfString) -> Option<String> {
pdf_string.to_string().map_or_else(
|error| {
tracing::error!(error = ?error, "Failed to convert PdfString to String");
None
},
|str| Some(str.trim().to_owned()),
)
}

impl From<InfoDict> for MediaMetadata {
fn from(dict: InfoDict) -> Self {
MediaMetadata {
title: dict.title.map(pdf_string_to_string).flatten(),
genre: dict
.subject
.map(pdf_string_to_string)
.flatten()
.map(|v| vec![v]),
year: dict.creation_date.as_ref().map(|date| date.year as i32),
month: dict.creation_date.as_ref().map(|date| date.month as i32),
day: dict.creation_date.as_ref().map(|date| date.day as i32),
writers: dict
.author
.map(pdf_string_to_string)
.flatten()
.map(|v| vec![v]),
..Default::default()
}
}
}

impl From<series_metadata::Data> for SeriesMetadata {
fn from(metadata: series_metadata::Data) -> Self {
SeriesMetadata {
Expand Down

0 comments on commit 28f78a6

Please sign in to comment.