From 62844b2073c1ceb0a12fdfaa08d6d245fe947c87 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 25 Aug 2025 18:47:54 -0300 Subject: [PATCH] fix: update bytes import and fix data_path field references Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/modes/server/api/item.rs | 2 +- src/services/async_item_service.rs | 34 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/modes/server/api/item.rs b/src/modes/server/api/item.rs index babca28..5eb2589 100644 --- a/src/modes/server/api/item.rs +++ b/src/modes/server/api/item.rs @@ -6,7 +6,6 @@ use axum::{ }; use log::warn; use std::collections::HashMap; -use bytes::Bytes; use crate::services::async_item_service::AsyncItemService; use crate::services::error::CoreError; @@ -14,6 +13,7 @@ use crate::modes::server::common::{AppState, ApiResponse, ItemInfo, TagsQuery, L use crate::common::is_binary::is_binary; use tokio::io::{AsyncReadExt, AsyncSeekExt}; use tokio_util::io::ReaderStream; +use tokio_util::bytes::Bytes; #[utoipa::path( get, diff --git a/src/services/async_item_service.rs b/src/services/async_item_service.rs index 78fb187..6b94b78 100644 --- a/src/services/async_item_service.rs +++ b/src/services/async_item_service.rs @@ -2,7 +2,6 @@ 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 bytes::Bytes; use rusqlite::Connection; use std::collections::HashMap; use std::path::PathBuf; @@ -10,6 +9,7 @@ use std::sync::Arc; use tokio::sync::Mutex; use tokio::io::{AsyncReadExt, AsyncSeekExt}; 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 @@ -22,17 +22,17 @@ pub struct AsyncItemService { #[allow(dead_code)] impl AsyncItemService { - pub fn new(data_path: PathBuf, db: Arc>) -> Self { - Self { data_path, db } + pub fn new(data_dir: PathBuf, db: Arc>) -> Self { + Self { data_dir, db } } pub async fn get_item(&self, id: i64) -> Result { - let data_path = self.data_path.clone(); + let data_dir = self.data_dir.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let conn = db.blocking_lock(); - let item_service = ItemService::new(data_path); + let item_service = ItemService::new(data_dir); item_service.get_item(&conn, id) }) .await @@ -40,12 +40,12 @@ impl AsyncItemService { } pub async fn get_item_content(&self, id: i64) -> Result { - let data_path = self.data_path.clone(); + let data_dir = self.data_dir.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let conn = db.blocking_lock(); - let item_service = ItemService::new(data_path); + let item_service = ItemService::new(data_dir); item_service.get_item_content(&conn, id) }) .await @@ -58,7 +58,7 @@ impl AsyncItemService { allow_binary: bool, offset: u64, length: u64, - ) -> Result<(impl tokio_stream::Stream>, String), CoreError> { + ) -> Result<(impl tokio_stream::Stream>, String), CoreError> { let item_with_content = self.get_item_content(item_id).await?; let metadata = item_with_content.item_with_meta.meta_as_map(); @@ -82,7 +82,7 @@ impl AsyncItemService { .unwrap_or_else(|| "application/octet-stream".to_string()); // Open the file for streaming - let file_path = self.data_path.join(format!("{}.dat", item_id)); + let file_path = self.data_dir.join(format!("{}.dat", item_id)); let file = tokio::fs::File::open(&file_path).await?; let mut buffered_file = tokio::io::BufReader::new(file); @@ -110,12 +110,12 @@ impl AsyncItemService { tags: Vec, meta: HashMap, ) -> Result { - let data_path = self.data_path.clone(); + let data_dir = self.data_dir.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let conn = db.blocking_lock(); - let item_service = ItemService::new(data_path); + let item_service = ItemService::new(data_dir); item_service.find_item(&conn, &ids, &tags, &meta) }) .await @@ -127,12 +127,12 @@ impl AsyncItemService { tags: Vec, meta: HashMap, ) -> Result, CoreError> { - let data_path = self.data_path.clone(); + let data_dir = self.data_dir.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let conn = db.blocking_lock(); - let item_service = ItemService::new(data_path); + let item_service = ItemService::new(data_dir); item_service.list_items(&conn, &tags, &meta) }) .await @@ -140,12 +140,12 @@ impl AsyncItemService { } pub async fn delete_item(&self, id: i64) -> Result<(), CoreError> { - let data_path = self.data_path.clone(); + let data_dir = self.data_dir.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let mut conn = db.blocking_lock(); - let item_service = ItemService::new(data_path); + let item_service = ItemService::new(data_dir); item_service.delete_item(&mut conn, id) }) .await @@ -158,12 +158,12 @@ impl AsyncItemService { tags: Vec, metadata: HashMap, ) -> Result { - let data_path = self.data_path.clone(); + let data_dir = self.data_dir.clone(); let db = self.db.clone(); tokio::task::spawn_blocking(move || { let mut conn = db.blocking_lock(); - let item_service = ItemService::new(data_path); + let item_service = ItemService::new(data_dir); item_service.save_item_from_mcp(&content, &tags, &metadata, &mut conn) }) .await