diff options
| author | 魏曹先生 <1992414357@qq.com> | 2025-11-06 22:11:18 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2025-11-06 22:11:18 +0800 |
| commit | f871f39ebfd22b8d7c86de1cc172db2d73a3bf9d (patch) | |
| tree | 2302b45418868e9cb8269e23188efa73c135893c /crates/vcs_data/src/data/local/cached_sheet.rs | |
| parent | 986a896062939c41f769b30c90d8d955b959f788 (diff) | |
feat: Add local data management modules (WIP)
- cached_sheet.rs: Cached sheet data management
- local_sheet.rs: Local sheet mapping structure
- member_held.rs: Member file holding status tracking
- NOTE: These modules are still under development
Diffstat (limited to 'crates/vcs_data/src/data/local/cached_sheet.rs')
| -rw-r--r-- | crates/vcs_data/src/data/local/cached_sheet.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/crates/vcs_data/src/data/local/cached_sheet.rs b/crates/vcs_data/src/data/local/cached_sheet.rs new file mode 100644 index 0000000..7ca1f2f --- /dev/null +++ b/crates/vcs_data/src/data/local/cached_sheet.rs @@ -0,0 +1,50 @@ +use std::{io::Error, path::PathBuf}; + +use cfg_file::config::ConfigFile; +use string_proc::snake_case; + +use crate::{ + constants::CLIENT_FILE_CACHED_SHEET, + current::current_local_path, + data::{ + member::MemberId, + sheet::{SheetData, SheetName}, + }, +}; + +const SHEET_NAME: &str = "{sheet_name}"; +const ACCOUNT_NAME: &str = "{account}"; + +pub struct CachedSheet; + +impl CachedSheet { + /// Read the cached sheet data. + pub async fn cached_sheet_data( + account_name: MemberId, + sheet_name: SheetName, + ) -> Result<SheetData, std::io::Error> { + let account_name = snake_case!(account_name); + let sheet_name = snake_case!(sheet_name); + + let Some(path) = Self::cached_sheet_path(account_name, sheet_name) else { + return Err(Error::new( + std::io::ErrorKind::NotFound, + "Local workspace not found!", + )); + }; + let data = SheetData::read_from(path).await?; + Ok(data) + } + + /// Get the path to the cached sheet file. + pub fn cached_sheet_path(account_name: MemberId, sheet_name: SheetName) -> Option<PathBuf> { + let current_workspace = current_local_path()?; + Some( + current_workspace.join( + CLIENT_FILE_CACHED_SHEET + .replace(SHEET_NAME, &sheet_name.to_string()) + .replace(ACCOUNT_NAME, &account_name.to_string()), + ), + ) + } +} |
