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/local_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/local_sheet.rs')
| -rw-r--r-- | crates/vcs_data/src/data/local/local_sheet.rs | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/crates/vcs_data/src/data/local/local_sheet.rs b/crates/vcs_data/src/data/local/local_sheet.rs new file mode 100644 index 0000000..63b73ac --- /dev/null +++ b/crates/vcs_data/src/data/local/local_sheet.rs @@ -0,0 +1,63 @@ +use std::{collections::HashMap, path::PathBuf}; + +use ::serde::{Deserialize, Serialize}; +use cfg_file::ConfigFile; +use chrono::NaiveDate; + +use crate::{ + constants::CLIENT_FILE_LOCAL_SHEET_NOSET, + data::vault::virtual_file::{VirtualFileId, VirtualFileVersionDescription}, +}; + +pub type LocalFilePathBuf = PathBuf; + +#[derive(Debug, Default, Serialize, Deserialize, ConfigFile)] +#[cfg_file(path = CLIENT_FILE_LOCAL_SHEET_NOSET)] // Do not use LocalSheet::write or LocalSheet::read +pub struct LocalSheet { + /// Local file path to virtual file ID mapping. + #[serde(rename = "mapping")] + mapping: HashMap<LocalFilePathBuf, MappingMetaData>, // Path to VFID +} + +#[derive(Debug, Default, Serialize, Deserialize)] +pub struct MappingMetaData { + /// Hash value generated immediately after the file is downloaded to the local workspace + #[serde(rename = "hash")] + hash_when_updated: String, + + /// Time when the file was downloaded to the local workspace + #[serde(rename = "date", with = "naive_date_serde")] + date_when_updated: NaiveDate, + + /// Size of the file when downloaded to the local workspace + #[serde(rename = "size")] + size_when_updated: u64, + + /// Version description when the file was downloaded to the local workspace + #[serde(rename = "version")] + version_desc_when_updated: VirtualFileVersionDescription, + + /// Virtual file ID corresponding to the local path + #[serde(rename = "id")] + mapping_vfid: VirtualFileId, +} + +mod naive_date_serde { + use chrono::NaiveDate; + use serde::{self, Deserialize, Deserializer, Serializer}; + + pub fn serialize<S>(date: &NaiveDate, serializer: S) -> Result<S::Ok, S::Error> + where + S: Serializer, + { + serializer.serialize_str(&date.format("%Y-%m-%d").to_string()) + } + + pub fn deserialize<'de, D>(deserializer: D) -> Result<NaiveDate, D::Error> + where + D: Deserializer<'de>, + { + let s = String::deserialize(deserializer)?; + NaiveDate::parse_from_str(&s, "%Y-%m-%d").map_err(serde::de::Error::custom) + } +} |
