refactor: Consolidate item content filtering into a single filter string
Co-authored-by: aider (openai/andrew/openrouter/deepseek/deepseek-chat-v3.1) <aider@aider.chat>
This commit is contained in:
@@ -392,6 +392,32 @@ pub async fn handle_get_item_content(
|
||||
debug!("ITEM_API: Getting content for item {} with stream={}, allow_binary={}, offset={}, length={}",
|
||||
item_id, params.stream, params.allow_binary, params.offset, params.length);
|
||||
|
||||
// Build filter string from query parameters
|
||||
let mut filter_parts = Vec::new();
|
||||
if let Some(head_bytes) = params.head_bytes {
|
||||
filter_parts.push(format!("head_bytes({})", head_bytes));
|
||||
}
|
||||
if let Some(head_lines) = params.head_lines {
|
||||
filter_parts.push(format!("head_lines({})", head_lines));
|
||||
}
|
||||
if let Some(tail_bytes) = params.tail_bytes {
|
||||
filter_parts.push(format!("tail_bytes({})", tail_bytes));
|
||||
}
|
||||
if let Some(tail_lines) = params.tail_lines {
|
||||
filter_parts.push(format!("tail_lines({})", tail_lines));
|
||||
}
|
||||
if let Some(grep) = params.grep {
|
||||
filter_parts.push(format!("grep({})", grep));
|
||||
}
|
||||
// Note: head_words, tail_words, line_start, line_end are not implemented in the filter system yet
|
||||
// You may need to add them to the filter syntax or handle them differently
|
||||
|
||||
let filter = if filter_parts.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(filter_parts.join(" | "))
|
||||
};
|
||||
|
||||
let item_service = AsyncItemService::new(
|
||||
state.data_dir.clone(),
|
||||
state.db.clone(),
|
||||
@@ -408,7 +434,7 @@ pub async fn handle_get_item_content(
|
||||
}
|
||||
result
|
||||
} else {
|
||||
let result = 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, filter).await;
|
||||
if let Ok(response) = &result {
|
||||
debug!("ITEM_API: Response content-length: {:?}", response.headers().get("content-length"));
|
||||
}
|
||||
@@ -423,6 +449,7 @@ async fn stream_item_content_response(
|
||||
offset: u64,
|
||||
length: u64,
|
||||
stream: bool,
|
||||
filter: Option<String>,
|
||||
) -> Result<Response, StatusCode> {
|
||||
debug!("STREAM_ITEM_CONTENT_RESPONSE: stream={}", stream);
|
||||
// Get the item with metadata once
|
||||
@@ -432,7 +459,7 @@ async fn stream_item_content_response(
|
||||
})?;
|
||||
|
||||
let metadata = item_with_meta.meta_as_map();
|
||||
stream_item_content_response_with_metadata(item_service, item_id, &metadata, allow_binary, offset, length, stream).await
|
||||
stream_item_content_response_with_metadata(item_service, item_id, &metadata, allow_binary, offset, length, stream, filter).await
|
||||
}
|
||||
|
||||
async fn stream_item_content_response_with_metadata(
|
||||
@@ -443,6 +470,7 @@ async fn stream_item_content_response_with_metadata(
|
||||
offset: u64,
|
||||
length: u64,
|
||||
stream: bool,
|
||||
filter: Option<String>,
|
||||
) -> Result<Response, StatusCode> {
|
||||
debug!("STREAM_ITEM_CONTENT_RESPONSE_WITH_METADATA: stream={}", stream);
|
||||
let mime_type = metadata
|
||||
@@ -481,15 +509,7 @@ async fn stream_item_content_response_with_metadata(
|
||||
true,
|
||||
offset,
|
||||
length,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None
|
||||
filter
|
||||
).await {
|
||||
Ok((stream, _)) => {
|
||||
let body = axum::body::Body::from_stream(stream);
|
||||
@@ -508,15 +528,7 @@ async fn stream_item_content_response_with_metadata(
|
||||
debug!("NON-STREAMING: Building full response in memory");
|
||||
match item_service.get_item_content_info(
|
||||
item_id,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
None
|
||||
filter
|
||||
).await {
|
||||
Ok((content, _, _)) => {
|
||||
// Apply offset and length
|
||||
|
||||
Reference in New Issue
Block a user