feat: add load file while load the dirs from the server.#1094
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
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;
| 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() |
There was a problem hiding this comment.
Avoid using unwrap() in production code as it may panic; consider propagating the error using proper error handling.
| 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(), | |
| }) |
| pub fn new() -> io::Result<Self> { | ||
| let store_path = config::store_path(); | ||
| let path = format!("{}/content.db", store_path); | ||
| let db = sled::open(path)?; |
There was a problem hiding this comment.
[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.
|
LGTM |
1.mono服务器添加一个api,返回文件的hash值
2.添加ContentStorage,类似于TreeStorage,保存加载的文件内容到数据库
3.添加文件内容加载,当加载目录的时候,也会检测文件内容变化进行加载
4.添加文件内容加载测试,mono添加文件或者修改文件后,本地加载目录会更新文件内容。