summaryrefslogtreecommitdiff
path: root/actions/src/remote_actions/sheet_manage
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-05 22:35:05 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-05 22:35:05 +0800
commit27f6414ad1ff451feb0044af62f37dc2a6255ffa (patch)
treecb5693bc014cc8579dcf02a730fd4d2a5dfcf1a5 /actions/src/remote_actions/sheet_manage
parentade2fcb9302a4ab759795820dbde3b2b269490ee (diff)
Remove examples and legacy code, update .gitignore
- Delete examples directory and its example action system - Rename actions/ to legacy_actions/ and data/ to legacy_data/ - Update Cargo.toml license file reference - Move setup scripts to scripts/dev/ directory - Add todo.txt patterns to .gitignore
Diffstat (limited to 'actions/src/remote_actions/sheet_manage')
-rw-r--r--actions/src/remote_actions/sheet_manage/drop_sheet.rs123
-rw-r--r--actions/src/remote_actions/sheet_manage/make_sheet.rs98
2 files changed, 0 insertions, 221 deletions
diff --git a/actions/src/remote_actions/sheet_manage/drop_sheet.rs b/actions/src/remote_actions/sheet_manage/drop_sheet.rs
deleted file mode 100644
index e21f3dd..0000000
--- a/actions/src/remote_actions/sheet_manage/drop_sheet.rs
+++ /dev/null
@@ -1,123 +0,0 @@
-use std::io::ErrorKind;
-
-use action_system::{action::ActionContext, macros::action_gen};
-use serde::{Deserialize, Serialize};
-use tcp_connection::error::TcpTargetError;
-use vcs_data::data::{local::modified_status::sign_vault_modified, sheet::SheetName};
-
-use crate::{
- remote_actions::{
- auth_member, check_connection_instance, try_get_local_workspace, try_get_vault,
- },
- write_and_return,
-};
-
-#[derive(Default, Serialize, Deserialize)]
-pub enum DropSheetActionResult {
- Success,
-
- // Fail
- SheetInUse,
- AuthorizeFailed(String),
- SheetNotExists,
- SheetDropFailed(String),
- NoHolder,
- NotOwner,
-
- #[default]
- Unknown,
-}
-
-#[action_gen]
-pub async fn drop_sheet_action(
- ctx: ActionContext,
- sheet_name: SheetName,
-) -> Result<DropSheetActionResult, TcpTargetError> {
- let instance = check_connection_instance(&ctx)?;
-
- // Auth Member
- let (member_id, is_host_mode) = match auth_member(&ctx, instance).await {
- Ok(id) => id,
- Err(e) => {
- return Ok(DropSheetActionResult::AuthorizeFailed(e.to_string()));
- }
- };
-
- // Check sheet in use on local
- if ctx.is_proc_on_local() {
- let local_workspace = try_get_local_workspace(&ctx)?;
- if let Some(sheet) = local_workspace.config().lock().await.sheet_in_use() {
- if sheet == &sheet_name {
- instance.lock().await.write(false).await?;
- return Ok(DropSheetActionResult::SheetInUse);
- }
- instance.lock().await.write(true).await?;
- } else {
- instance.lock().await.write(true).await?;
- }
- }
-
- if ctx.is_proc_on_remote() {
- // Check if client sheet is in use
- let sheet_in_use = instance.lock().await.read::<bool>().await?;
- if !sheet_in_use {
- return Ok(DropSheetActionResult::SheetInUse);
- }
-
- let vault = try_get_vault(&ctx)?;
-
- // Check if the sheet exists
- let mut sheet = match vault.sheet(&sheet_name).await {
- Ok(sheet) => sheet,
- Err(e) => {
- if e.kind() == ErrorKind::NotFound {
- write_and_return!(instance, DropSheetActionResult::SheetNotExists);
- } else {
- write_and_return!(
- instance,
- DropSheetActionResult::SheetDropFailed(e.to_string())
- );
- }
- }
- };
-
- // Get the sheet's holder
- let Some(holder) = sheet.holder() else {
- write_and_return!(instance, DropSheetActionResult::NoHolder);
- };
-
- // Verify that the sheet holder is either the current user or the host
- // All sheets belong to the host
- if holder != &member_id && !is_host_mode {
- write_and_return!(instance, DropSheetActionResult::NotOwner);
- }
-
- // Drop the sheet
- sheet.forget_holder();
- match sheet.persist().await {
- Ok(_) => {
- write_and_return!(instance, DropSheetActionResult::Success);
- }
- Err(e) => {
- write_and_return!(
- instance,
- DropSheetActionResult::SheetDropFailed(e.to_string())
- );
- }
- }
- }
-
- if ctx.is_proc_on_local() {
- let result = instance
- .lock()
- .await
- .read::<DropSheetActionResult>()
- .await?;
- if matches!(result, DropSheetActionResult::Success) {
- sign_vault_modified(true).await;
- }
- return Ok(result);
- }
-
- Err(TcpTargetError::NoResult("No result.".to_string()))
-}
diff --git a/actions/src/remote_actions/sheet_manage/make_sheet.rs b/actions/src/remote_actions/sheet_manage/make_sheet.rs
deleted file mode 100644
index a323413..0000000
--- a/actions/src/remote_actions/sheet_manage/make_sheet.rs
+++ /dev/null
@@ -1,98 +0,0 @@
-use action_system::{action::ActionContext, macros::action_gen};
-use serde::{Deserialize, Serialize};
-use tcp_connection::error::TcpTargetError;
-use vcs_data::{
- constants::VAULT_HOST_NAME,
- data::{local::modified_status::sign_vault_modified, sheet::SheetName},
-};
-
-use crate::{
- remote_actions::{auth_member, check_connection_instance, try_get_vault},
- write_and_return,
-};
-
-#[derive(Default, Serialize, Deserialize)]
-pub enum MakeSheetActionResult {
- Success,
- SuccessRestore,
-
- // Fail
- AuthorizeFailed(String),
- SheetAlreadyExists,
- SheetCreationFailed(String),
-
- #[default]
- Unknown,
-}
-
-/// Build a sheet with context
-#[action_gen]
-pub async fn make_sheet_action(
- ctx: ActionContext,
- sheet_name: SheetName,
-) -> Result<MakeSheetActionResult, TcpTargetError> {
- let instance = check_connection_instance(&ctx)?;
-
- // Auth Member
- let (member_id, is_host_mode) = match auth_member(&ctx, instance).await {
- Ok(id) => id,
- Err(e) => return Ok(MakeSheetActionResult::AuthorizeFailed(e.to_string())),
- };
-
- if ctx.is_proc_on_remote() {
- let vault = try_get_vault(&ctx)?;
- let holder = if is_host_mode {
- VAULT_HOST_NAME.to_string()
- } else {
- member_id
- };
-
- // Check if the sheet already exists
- if let Ok(mut sheet) = vault.sheet(&sheet_name).await {
- // If the sheet has no holder, assign it to the current member (restore operation)
- if sheet.holder().is_none() {
- sheet.set_holder(holder.clone());
- match sheet.persist().await {
- Ok(_) => {
- write_and_return!(instance, MakeSheetActionResult::SuccessRestore);
- }
- Err(e) => {
- write_and_return!(
- instance,
- MakeSheetActionResult::SheetCreationFailed(e.to_string())
- );
- }
- }
- } else {
- write_and_return!(instance, MakeSheetActionResult::SheetAlreadyExists);
- }
- } else {
- // Create the sheet
- match vault.create_sheet(&sheet_name, &holder).await {
- Ok(_) => {
- write_and_return!(instance, MakeSheetActionResult::Success);
- }
- Err(e) => {
- write_and_return!(
- instance,
- MakeSheetActionResult::SheetCreationFailed(e.to_string())
- );
- }
- }
- }
- }
-
- if ctx.is_proc_on_local() {
- let result = instance
- .lock()
- .await
- .read::<MakeSheetActionResult>()
- .await?;
- if matches!(result, MakeSheetActionResult::Success) {
- sign_vault_modified(true).await;
- }
- return Ok(result);
- }
-
- Err(TcpTargetError::NoResult("No result.".to_string()))
-}