From 759221a3001504cfd5c758e4fa70d4c2dac4e07c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 6 Nov 2025 22:10:15 +0800 Subject: feat: Enhanced data structures and constants - Add new constants for local workspace management - Extend SheetData with write_count functionality - Simplify vault data structures - Update sheet and virtual file data handling --- crates/vcs_data/src/data/sheet.rs | 21 ++++++++++- crates/vcs_data/src/data/vault.rs | 49 ++------------------------ crates/vcs_data/src/data/vault/sheets.rs | 1 + crates/vcs_data/src/data/vault/virtual_file.rs | 2 +- 4 files changed, 24 insertions(+), 49 deletions(-) (limited to 'crates/vcs_data/src/data') diff --git a/crates/vcs_data/src/data/sheet.rs b/crates/vcs_data/src/data/sheet.rs index 69dc27d..09271d5 100644 --- a/crates/vcs_data/src/data/sheet.rs +++ b/crates/vcs_data/src/data/sheet.rs @@ -50,6 +50,9 @@ pub struct Sheet<'a> { #[derive(Default, Serialize, Deserialize, ConfigFile, Clone)] pub struct SheetData { + /// The write count of the current sheet + pub(crate) write_count: i32, + /// The holder of the current sheet, who has full operation rights to the sheet mapping pub(crate) holder: Option, @@ -89,6 +92,11 @@ impl<'a> Sheet<'a> { &self.data.mapping } + /// Get the write count of this sheet + pub fn write_count(&self) -> i32 { + self.data.write_count + } + /// Forget the holder of this sheet pub fn forget_holder(&mut self) { self.data.holder = None; @@ -263,7 +271,11 @@ impl<'a> Sheet<'a> { /// Why not use a reference? /// Because I don't want a second instance of the sheet to be kept in memory. /// If needed, please deserialize and reload it. - pub async fn persist(self) -> Result<(), std::io::Error> { + pub async fn persist(mut self) -> Result<(), std::io::Error> { + self.data.write_count += 1; + if self.data.write_count > i32::MAX { + self.data.write_count = 0; + } SheetData::write_to(&self.data, self.sheet_path()).await } @@ -384,3 +396,10 @@ impl<'a> Sheet<'a> { self.data } } + +impl SheetData { + /// Get the write count of this sheet data + pub fn write_count(&self) -> i32 { + self.write_count + } +} diff --git a/crates/vcs_data/src/data/vault.rs b/crates/vcs_data/src/data/vault.rs index efb4eec..fedebb3 100644 --- a/crates/vcs_data/src/data/vault.rs +++ b/crates/vcs_data/src/data/vault.rs @@ -6,6 +6,7 @@ use std::{ }; use cfg_file::config::ConfigFile; +use vcs_docs::docs::READMES_VAULT_README; use crate::{ constants::{ @@ -94,53 +95,7 @@ impl Vault { .await?; // Final, generate README.md - let readme_content = format!( - "\ -# JustEnoughVCS Server Setup - -This directory contains the server configuration and data for `JustEnoughVCS`. - -## User Authentication -To allow users to connect to this server, place their public keys in the `{}` directory. -Each public key file should be named `{{member_id}}.pem` (e.g., `juliet.pem`), and contain the user's public key in PEM format. - -**ECDSA:** -```bash -openssl genpkey -algorithm ed25519 -out your_name_private.pem -openssl pkey -in your_name_private.pem -pubout -out your_name.pem -``` - -**RSA:** -```bash -openssl genpkey -algorithm RSA -out your_name_private.pem -pkeyopt rsa_keygen_bits:2048 -openssl pkey -in your_name_private.pem -pubout -out your_name.pem -``` - -**DSA:** -```bash -openssl genpkey -algorithm DSA -out your_name_private.pem -pkeyopt dsa_paramgen_bits:2048 -openssl pkey -in your_name_private.pem -pubout -out your_name.pem -``` - -Place only the `your_name.pem` file in the server's `./key/` directory, renamed to match the user's member ID. - -## File Storage -All version-controlled files (Virtual File) are stored in the `{}` directory. - -## License -This software is distributed under the MIT License. For complete license details, please see the main repository homepage. - -## Support -Repository: `https://github.com/JustEnoughVCS/VersionControl` -Please report any issues or questions on the GitHub issue tracker. - -## Thanks :) -Thank you for using `JustEnoughVCS!` - ", - SERVER_PATH_MEMBER_PUB, SERVER_PATH_VF_ROOT - ) - .trim() - .to_string(); + let readme_content = READMES_VAULT_README; fs::write(vault_path.join(SERVER_FILE_README), readme_content)?; Ok(()) diff --git a/crates/vcs_data/src/data/vault/sheets.rs b/crates/vcs_data/src/data/vault/sheets.rs index 1407350..ba021b5 100644 --- a/crates/vcs_data/src/data/vault/sheets.rs +++ b/crates/vcs_data/src/data/vault/sheets.rs @@ -133,6 +133,7 @@ impl Vault { holder: Some(holder.clone()), inputs: Vec::new(), mapping: HashMap::new(), + write_count: 0, }; SheetData::write_to(&sheet_data, sheet_file_path).await?; diff --git a/crates/vcs_data/src/data/vault/virtual_file.rs b/crates/vcs_data/src/data/vault/virtual_file.rs index fe83594..221766f 100644 --- a/crates/vcs_data/src/data/vault/virtual_file.rs +++ b/crates/vcs_data/src/data/vault/virtual_file.rs @@ -51,7 +51,7 @@ pub struct VirtualFileMeta { histories: Vec, } -#[derive(Default, Clone, Serialize, Deserialize)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct VirtualFileVersionDescription { /// The member who created this version pub creator: MemberId, -- cgit