refactor: extract content info logic to item_service
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -245,22 +245,32 @@ async fn stream_item_content_response(
|
||||
|
||||
// Check if content is binary when allow_binary is false
|
||||
if !allow_binary {
|
||||
let is_content_binary = if let Some(binary_val) = metadata.get("binary") {
|
||||
binary_val == "true"
|
||||
} else {
|
||||
// For the binary check, we need to read a sample of the content
|
||||
match item_service.get_item_content(item_id).await {
|
||||
Ok(item_with_content) => {
|
||||
crate::common::is_binary::is_binary(&item_with_content.content)
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to get content for binary check for item {}: {}", item_id, e);
|
||||
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
// Get the binary status using the new method
|
||||
let is_binary = match item_service.get_item(item_id).await {
|
||||
Ok(item_with_meta) => {
|
||||
let metadata = item_with_meta.meta_as_map();
|
||||
if let Some(binary_val) = metadata.get("binary") {
|
||||
binary_val == "true"
|
||||
} else {
|
||||
// Fall back to checking the content directly
|
||||
match item_service.get_item_content(item_id).await {
|
||||
Ok(item_with_content) => {
|
||||
crate::common::is_binary::is_binary(&item_with_content.content)
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to get content for binary check for item {}: {}", item_id, e);
|
||||
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to get item {} for binary check: {}", item_id, e);
|
||||
return Err(StatusCode::INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
};
|
||||
|
||||
if is_content_binary {
|
||||
if is_binary {
|
||||
return Err(StatusCode::BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user