Refactor Pandoc command to use the PandocProcessBuilder

This commit is contained in:
Thorsten Sommer 2025-05-30 22:32:00 +02:00
parent b3a9c2057b
commit 746d103274
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

@ -7,7 +7,6 @@ use file_format::{FileFormat, Kind};
use futures::{Stream, StreamExt}; use futures::{Stream, StreamExt};
use pdfium_render::prelude::Pdfium; use pdfium_render::prelude::Pdfium;
use tokio::io::AsyncBufReadExt; use tokio::io::AsyncBufReadExt;
use tokio::process::Command;
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
use rocket::Shutdown; use rocket::Shutdown;
@ -16,6 +15,7 @@ use rocket::tokio::select;
use rocket::serde::Serialize; use rocket::serde::Serialize;
use rocket::get; use rocket::get;
use crate::api_token::APIToken; use crate::api_token::APIToken;
use crate::pandoc::PandocProcessBuilder;
use crate::pdfium::PdfiumInit; use crate::pdfium::PdfiumInit;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -255,11 +255,12 @@ async fn convert_with_pandoc(
from: &str, from: &str,
to: &str, to: &str,
) -> Result<ChunkStream> { ) -> Result<ChunkStream> {
let output = Command::new("pandoc") let output = PandocProcessBuilder::new()
.arg(file_path) .with_input_file(file_path)
.args(["-f", from, "-t", to]) .with_input_format(from)
.output() .with_output_format(to)
.await?; .build()
.command.output().await?;
let stream = stream! { let stream = stream! {
if output.status.success() { if output.status.success() {