opentalk_roomserver_report_generation/
lib.rs1mod report_date_time;
13mod report_generation_error;
14mod world;
15
16use std::{borrow::Cow, collections::BTreeMap, path::Path};
17
18pub use report_date_time::{ReportDateTime, ToReportDateTime};
19pub use report_generation_error::ReportGenerationError;
20use typst::{World as _, diag::SourceResult};
21use typst_pdf::PdfOptions;
22use world::World;
23
24pub fn generate_pdf_report(
26 source: String,
27 data: BTreeMap<&Path, Cow<'static, [u8]>>,
28) -> Result<Vec<u8>, ReportGenerationError> {
29 let world = World::new(source, data);
30
31 let report = match generate_pdf_report_inner(&world) {
32 Ok(d) => d,
33 Err(e) => {
34 for diagnostic in &e {
35 if let Ok(source) = world.source(*world::MAIN_ID) {
36 let range = source.range(diagnostic.span);
37 tracing::warn!("{}: {:?}", diagnostic.message, range);
38 }
39 }
40 return Err(e.into());
41 }
42 };
43
44 Ok(report)
45}
46
47fn generate_pdf_report_inner(world: &World) -> SourceResult<Vec<u8>> {
48 let document = typst::compile(&world).output?;
49 typst_pdf::pdf(&document, &PdfOptions::default())
50}