feat: add debug logging for item content streaming
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -236,6 +236,9 @@ pub async fn handle_get_item_content(
|
|||||||
return Err(StatusCode::BAD_REQUEST);
|
return Err(StatusCode::BAD_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug!("ITEM_API: Getting content for item {} with stream={}, allow_binary={}, offset={}, length={}",
|
||||||
|
item_id, params.stream, params.allow_binary, params.offset, params.length);
|
||||||
|
|
||||||
let item_service = AsyncItemService::new(
|
let item_service = AsyncItemService::new(
|
||||||
state.data_dir.clone(),
|
state.data_dir.clone(),
|
||||||
state.db.clone(),
|
state.db.clone(),
|
||||||
@@ -243,7 +246,12 @@ pub async fn handle_get_item_content(
|
|||||||
state.cmd.clone(),
|
state.cmd.clone(),
|
||||||
state.settings.clone()
|
state.settings.clone()
|
||||||
);
|
);
|
||||||
stream_item_content_response(&item_service, item_id, params.allow_binary, params.offset, params.length, params.stream).await
|
let result = stream_item_content_response(&item_service, item_id, params.allow_binary, params.offset, params.length, params.stream).await;
|
||||||
|
|
||||||
|
if let Ok(response) = &result {
|
||||||
|
debug!("ITEM_API: Response content-length: {:?}", response.headers().get("content-length"));
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn stream_item_content_response(
|
async fn stream_item_content_response(
|
||||||
@@ -254,6 +262,7 @@ async fn stream_item_content_response(
|
|||||||
length: u64,
|
length: u64,
|
||||||
stream: bool,
|
stream: bool,
|
||||||
) -> Result<Response, StatusCode> {
|
) -> Result<Response, StatusCode> {
|
||||||
|
debug!("STREAM_ITEM_CONTENT_RESPONSE: stream={}", stream);
|
||||||
// Get the item with metadata once
|
// Get the item with metadata once
|
||||||
let item_with_meta = item_service.get_item(item_id).await.map_err(|e| {
|
let item_with_meta = item_service.get_item(item_id).await.map_err(|e| {
|
||||||
warn!("Failed to get item {} for content: {}", item_id, e);
|
warn!("Failed to get item {} for content: {}", item_id, e);
|
||||||
@@ -273,6 +282,7 @@ async fn stream_item_content_response_with_metadata(
|
|||||||
length: u64,
|
length: u64,
|
||||||
stream: bool,
|
stream: bool,
|
||||||
) -> Result<Response, StatusCode> {
|
) -> Result<Response, StatusCode> {
|
||||||
|
debug!("STREAM_ITEM_CONTENT_RESPONSE_WITH_METADATA: stream={}", stream);
|
||||||
let mime_type = metadata
|
let mime_type = metadata
|
||||||
.get("mime_type")
|
.get("mime_type")
|
||||||
.map(|s| s.to_string())
|
.map(|s| s.to_string())
|
||||||
@@ -299,7 +309,7 @@ async fn stream_item_content_response_with_metadata(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if stream {
|
if stream {
|
||||||
// Stream the content
|
debug!("STREAMING: Using streaming approach");
|
||||||
match item_service.stream_item_content_by_id_with_metadata(item_id, metadata, true, offset, length).await {
|
match item_service.stream_item_content_by_id_with_metadata(item_id, metadata, true, offset, length).await {
|
||||||
Ok((stream, _)) => {
|
Ok((stream, _)) => {
|
||||||
let body = axum::body::Body::from_stream(stream);
|
let body = axum::body::Body::from_stream(stream);
|
||||||
@@ -315,7 +325,7 @@ async fn stream_item_content_response_with_metadata(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Build the full response in memory
|
debug!("NON-STREAMING: Building full response in memory");
|
||||||
match item_service.get_item_content_info(item_id).await {
|
match item_service.get_item_content_info(item_id).await {
|
||||||
Ok((content, _, _)) => {
|
Ok((content, _, _)) => {
|
||||||
// Apply offset and length
|
// Apply offset and length
|
||||||
@@ -333,8 +343,12 @@ async fn stream_item_content_response_with_metadata(
|
|||||||
&[]
|
&[]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug!("NON-STREAMING: Content length: {}, start: {}, end: {}, response length: {}",
|
||||||
|
content_len, start, end, response_content.len());
|
||||||
|
|
||||||
let response = Response::builder()
|
let response = Response::builder()
|
||||||
.header(header::CONTENT_TYPE, mime_type)
|
.header(header::CONTENT_TYPE, mime_type)
|
||||||
|
.header(header::CONTENT_LENGTH, response_content.len().to_string())
|
||||||
.body(axum::body::Body::from(response_content.to_vec()))
|
.body(axum::body::Body::from(response_content.to_vec()))
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
Ok(response)
|
Ok(response)
|
||||||
|
|||||||
Reference in New Issue
Block a user