fix: remove unused imports and fix field access errors
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
use crate::services::error::CoreError;
|
||||
use crate::services::item_service::ItemService;
|
||||
use crate::services::types::{ItemWithContent, ItemWithMeta};
|
||||
use crate::common::is_binary::is_binary;
|
||||
use rusqlite::Connection;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::io::{AsyncReadExt, AsyncSeekExt};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio_util::io::ReaderStream;
|
||||
use tokio_util::bytes::Bytes;
|
||||
|
||||
/// An asynchronous wrapper around the `ItemService` for use in async contexts like the web server.
|
||||
/// It uses `tokio::task::spawn_blocking` to run synchronous database and filesystem operations
|
||||
@@ -62,7 +61,7 @@ impl AsyncItemService {
|
||||
) -> Result<(std::pin::Pin<Box<dyn tokio_stream::Stream<Item = Result<tokio_util::bytes::Bytes, std::io::Error>> + Send>>, String), CoreError> {
|
||||
// First get the item to determine compression type
|
||||
let item_with_meta = self.get_item(item_id).await?;
|
||||
let metadata = item_with_meta.item_with_meta.meta_as_map();
|
||||
let metadata = item_with_meta.meta_as_map();
|
||||
|
||||
// Check if content is binary when allow_binary is false
|
||||
if !allow_binary {
|
||||
@@ -90,7 +89,7 @@ impl AsyncItemService {
|
||||
let file_path = self.data_dir.join(item_id.to_string());
|
||||
|
||||
// Get the compression engine to decompress while streaming
|
||||
let compression_type = crate::compression_engine::CompressionType::from_str(&item_with_meta.item_with_meta.item.compression)
|
||||
let compression_type = crate::compression_engine::CompressionType::from_str(&item_with_meta.item.compression)
|
||||
.map_err(|e| CoreError::Compression(e.to_string()))?;
|
||||
let engine = crate::compression_engine::get_compression_engine(compression_type)
|
||||
.map_err(|e| CoreError::Other(anyhow::anyhow!(e.to_string())))?;
|
||||
@@ -99,26 +98,14 @@ impl AsyncItemService {
|
||||
let reader = engine.open(file_path)
|
||||
.map_err(|e| CoreError::Other(anyhow::anyhow!("Failed to open item file: {}", e)))?;
|
||||
|
||||
// Wrap in async reader
|
||||
let async_reader = tokio_util::io::SyncIoBridge::new(reader);
|
||||
let mut buffered_reader = tokio::io::BufReader::new(async_reader);
|
||||
|
||||
// Seek to the requested offset if needed (this is complex with compressed data)
|
||||
// For now, we'll note this limitation in the API
|
||||
if offset > 0 {
|
||||
// Seeking in compressed streams is non-trivial and would require decompressing
|
||||
// up to the offset. This is a limitation of the current implementation.
|
||||
log::warn!("Offset parameter not supported for compressed content streaming");
|
||||
}
|
||||
|
||||
// Create a reader stream - this needs to respect the length parameter
|
||||
// Create a reader stream directly from the reader
|
||||
let stream: std::pin::Pin<Box<dyn tokio_stream::Stream<Item = Result<tokio_util::bytes::Bytes, std::io::Error>> + Send>> =
|
||||
if length > 0 {
|
||||
// Limit the stream to the specified length
|
||||
Box::pin(ReaderStream::new(buffered_reader.take(length)))
|
||||
Box::pin(ReaderStream::new(reader.take(length)))
|
||||
} else {
|
||||
// Stream the entire decompressed file
|
||||
Box::pin(ReaderStream::new(buffered_reader))
|
||||
Box::pin(ReaderStream::new(reader))
|
||||
};
|
||||
|
||||
Ok((stream, mime_type))
|
||||
|
||||
Reference in New Issue
Block a user