Skip to content

feat: add load file while load the dirs from the server.#1094

Merged
genedna merged 2 commits into
gitmono-dev:mainfrom
yyjeqhc:load_file
Jun 5, 2025
Merged

feat: add load file while load the dirs from the server.#1094
genedna merged 2 commits into
gitmono-dev:mainfrom
yyjeqhc:load_file

Conversation

@yyjeqhc

@yyjeqhc yyjeqhc commented Jun 4, 2025

Copy link
Copy Markdown
Contributor

1.mono服务器添加一个api,返回文件的hash值
2.添加ContentStorage,类似于TreeStorage,保存加载的文件内容到数据库
3.添加文件内容加载,当加载目录的时候,也会检测文件内容变化进行加载
4.添加文件内容加载测试,mono添加文件或者修改文件后,本地加载目录会更新文件内容。

@vercel

vercel Bot commented Jun 4, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mega ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 5, 2025 5:09am

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for loading file contents when loading directories from the server, including a new API to return file hashes and testing for file modification updates.

  • Introduces ContentStorage to persist file contents and updates DictionaryStore to load files into memory.
  • Adds a new API endpoint and updates tests to verify that file content changes are detected and loaded.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vault/src/pgp.rs Reordered import statements for clarity.
scorpio/tests/dir_test.rs Added a new SCORCommand (ReadFileContent) and updated test flows to verify file content.
scorpio/src/main.rs Minor formatting update in the main function.
scorpio/src/dicfuse/store.rs Extended DictionaryStore with file-content handling methods and new fields.
scorpio/src/dicfuse/mod.rs Refactored Dicfuse to rely on the new file-content APIs from DictionaryStore.
scorpio/src/dicfuse/content_store.rs Introduced ContentStorage for persisting file contents using sled.
scorpio/src/dicfuse/async_io.rs Updated async I/O to retrieve file content via the new store methods.
mono/src/api/api_router.rs Added a new API route for fetching tree content hashes.
ceres/src/api_service/mod.rs Implemented get_tree_content_hash in the API service to support file content hash retrieval.
Comments suppressed due to low confidence (2)

ceres/src/api_service/mod.rs:261

  • Using unwrap() here could lead to a panic if commit retrieval fails; it's recommended to handle the error gracefully.
let commits = self.get_commits_by_hashes(commit_ids.into_iter().collect()).await.unwrap();

ceres/src/api_service/mod.rs:238

  • [nitpick] If the commented-out add_blobs_to_map block is no longer needed, consider removing it to improve code clarity.
// self.add_blobs_to_map(...).await;

Comment on lines +197 to +223
async fn fetch_file(oid: &str) -> Vec<u8> {
let file_blob_endpoint = config::file_blob_endpoint();
let url = format!("{}/{}", file_blob_endpoint, oid);
let client = Client::new();

// Send GET request
let response = client.get(url).send().await.unwrap(); //todo error

// Ensure that the response status is successful
if response.status().is_success() {
// Get the binary data from the response body
let content = response.bytes().await.unwrap(); //TODO error
return content.to_vec();
}
Vec::new()

Copilot AI Jun 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using unwrap() in production code as it may panic; consider propagating the error using proper error handling.

Suggested change
async fn fetch_file(oid: &str) -> Vec<u8> {
let file_blob_endpoint = config::file_blob_endpoint();
let url = format!("{}/{}", file_blob_endpoint, oid);
let client = Client::new();
// Send GET request
let response = client.get(url).send().await.unwrap(); //todo error
// Ensure that the response status is successful
if response.status().is_success() {
// Get the binary data from the response body
let content = response.bytes().await.unwrap(); //TODO error
return content.to_vec();
}
Vec::new()
async fn fetch_file(oid: &str) -> Result<Vec<u8>, DictionaryError> {
let file_blob_endpoint = config::file_blob_endpoint();
let url = format!("{}/{}", file_blob_endpoint, oid);
let client = Client::new();
// Send GET request
let response = client.get(url).send().await.map_err(|e| DictionaryError {
message: format!("Failed to send GET request: {}", e),
})?;
// Ensure that the response status is successful
if response.status().is_success() {
// Get the binary data from the response body
let content = response.bytes().await.map_err(|e| DictionaryError {
message: format!("Failed to read response bytes: {}", e),
})?;
return Ok(content.to_vec());
}
Err(DictionaryError {
message: "Response status was not successful".to_string(),
})

Copilot uses AI. Check for mistakes.
pub fn new() -> io::Result<Self> {
let store_path = config::store_path();
let path = format!("{}/content.db", store_path);
let db = sled::open(path)?;

Copilot AI Jun 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using sled in an async context might block the async runtime; consider offloading DB access to a blocking thread pool or switching to an async-compatible database driver.

Copilot uses AI. Check for mistakes.

@benjamin-747 benjamin-747 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ivanbeethoven

Copy link
Copy Markdown
Collaborator

LGTM

Merged via the queue into gitmono-dev:main with commit d7b7d2c Jun 5, 2025
14 checks passed
@yyjeqhc
yyjeqhc deleted the load_file branch August 4, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants