From 8ebd25bbb8cbd18c02f4479d775656abae21b1e2 Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Tue, 12 May 2026 20:30:20 +0200 Subject: [PATCH] Added case-insensitive bool deserialization for queries --- runtime/src/file_data.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/runtime/src/file_data.rs b/runtime/src/file_data.rs index d41a9daa..43446f46 100644 --- a/runtime/src/file_data.rs +++ b/runtime/src/file_data.rs @@ -13,9 +13,11 @@ use file_format::{FileFormat, Kind}; use futures::{Stream, StreamExt}; use pdfium_render::prelude::Pdfium; use pptx_to_md::{ImageHandlingMode, ParserConfig, PptxContainer}; -use serde::{Deserialize, Serialize}; +use serde::{Deserialize, Deserializer, Serialize}; +use serde::de::{Error as SerdeError, Visitor}; use std::path::Path; use std::pin::Pin; +use std::fmt; use log::{debug, error, warn}; use tokio::io::AsyncBufReadExt; use tokio::sync::mpsc; @@ -86,9 +88,42 @@ type ChunkStream = Pin> + Send>>; pub struct ExtractDataQuery { path: String, stream_id: String, + #[serde(deserialize_with = "deserialize_bool_case_insensitive")] extract_images: bool, } +fn deserialize_bool_case_insensitive<'de, D>(deserializer: D) -> std::result::Result +where + D: Deserializer<'de>, +{ + struct BoolVisitor; + + impl<'de> Visitor<'de> for BoolVisitor { + type Value = bool; + + fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("a boolean value") + } + + fn visit_bool(self, value: bool) -> std::result::Result { + Ok(value) + } + + fn visit_str(self, value: &str) -> std::result::Result + where + E: SerdeError, + { + match value.to_ascii_lowercase().as_str() { + "true" | "1" => Ok(true), + "false" | "0" => Ok(false), + _ => Err(E::invalid_value(serde::de::Unexpected::Str(value), &self)), + } + } + } + + deserializer.deserialize_any(BoolVisitor) +} + pub async fn extract_data( _token: APIToken, query: std::result::Result, QueryRejection>,