From c3dd017b257cc7aebdec7c74d5ff55b25de4f45f Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 25 Aug 2025 18:39:59 -0300 Subject: [PATCH] feat: use item content for binary detection Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/modes/server/api/item.rs | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/modes/server/api/item.rs b/src/modes/server/api/item.rs index d304440..3b0cc59 100644 --- a/src/modes/server/api/item.rs +++ b/src/modes/server/api/item.rs @@ -208,28 +208,16 @@ async fn stream_item_content( offset: u64, length: u64, ) -> anyhow::Result<(impl tokio_stream::Stream>, String)> { - let item_with_meta = service.get_item(item_id).await?; - let metadata = item_with_meta.meta_as_map(); + let item_with_content = service.get_item_content(item_id).await?; + let metadata = item_with_content.item_with_meta.meta_as_map(); // Check if content is binary when allow_binary is false if !allow_binary { - let is_content_binary = if let Some(binary_meta) = metadata.get("binary") { - binary_meta == "true" + let is_content_binary = if let Some(binary_val) = metadata.get("binary") { + binary_val == "true" } else { - // If binary metadata not available, we need to check the file content - // Read the first 8192 bytes to determine if it's binary - let file_path = service.data_dir.join(format!("{}.dat", item_id)); - if let Ok(mut file) = tokio::fs::File::open(&file_path).await { - let mut buffer = vec![0; 8192]; - if let Ok(bytes_read) = file.read(&mut buffer).await { - buffer.truncate(bytes_read); - is_binary(&buffer) - } else { - false // Default to non-binary if we can't read - } - } else { - false // Default to non-binary if we can't open the file - } + // If binary metadata not available, check the actual content + is_binary(&item_with_content.content) }; if is_content_binary {