diff --git a/markbase-tauri/src-tauri/src/commands/mod.rs b/markbase-tauri/src-tauri/src/commands/mod.rs index 03752b3..72d5c68 100644 --- a/markbase-tauri/src-tauri/src/commands/mod.rs +++ b/markbase-tauri/src-tauri/src/commands/mod.rs @@ -7,6 +7,7 @@ pub mod health; pub mod monitor; pub mod backup; pub mod user_management; +pub mod share_management; pub use file_ops::*; pub use install::*; @@ -16,4 +17,5 @@ pub use management::*; pub use health::*; pub use monitor::*; pub use backup::*; -pub use user_management::*; \ No newline at end of file +pub use user_management::*; +pub use share_management::*; \ No newline at end of file diff --git a/markbase-tauri/src-tauri/src/commands/share_management.rs b/markbase-tauri/src-tauri/src/commands/share_management.rs new file mode 100644 index 0000000..6a81195 --- /dev/null +++ b/markbase-tauri/src-tauri/src/commands/share_management.rs @@ -0,0 +1,152 @@ +use serde::{Serialize, Deserialize}; +use std::path::PathBuf; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct ShareInfo { + pub name: String, + pub path: String, + pub protocol: String, + pub users: Vec, + pub permissions: String, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct ConnectionTestResult { + pub success: bool, + pub error: Option, +} + +lazy_static::lazy_static! { + static ref SHARES: std::sync::Arc>> = + std::sync::Arc::new(std::sync::Mutex::new(Vec::new())); +} + +#[tauri::command] +pub async fn list_shares() -> Result, String> { + let shares = SHARES.lock().unwrap(); + Ok(shares.clone()) +} + +#[tauri::command] +pub async fn create_share( + name: String, + path: String, + protocol: String, + users: Vec, + permissions: String, +) -> Result<(), String> { + let mut shares = SHARES.lock().unwrap(); + + if shares.iter().any(|s| s.name == name) { + return Err(format!("Share '{}' already exists", name)); + } + + let path_buf = PathBuf::from(&path); + if !path_buf.exists() { + std::fs::create_dir_all(&path_buf) + .map_err(|e| format!("Failed to create directory: {}", e))?; + } + + shares.push(ShareInfo { + name, + path, + protocol, + users, + permissions, + }); + + Ok(()) +} + +#[tauri::command] +pub async fn update_share( + name: String, + path: String, + protocol: String, + users: Vec, + permissions: String, +) -> Result<(), String> { + let mut shares = SHARES.lock().unwrap(); + + let share = shares.iter_mut().find(|s| s.name == name); + if share.is_none() { + return Err(format!("Share '{}' not found", name)); + } + + let share = share.unwrap(); + share.path = path; + share.protocol = protocol; + share.users = users; + share.permissions = permissions; + + Ok(()) +} + +#[tauri::command] +pub async fn delete_share(name: String) -> Result<(), String> { + let mut shares = SHARES.lock().unwrap(); + + let index = shares.iter().position(|s| s.name == name); + if index.is_none() { + return Err(format!("Share '{}' not found", name)); + } + + shares.remove(index.unwrap()); + Ok(()) +} + +#[tauri::command] +pub async fn test_share_connection( + name: String, + protocol: String, +) -> Result { + let shares = SHARES.lock().unwrap(); + + let share = shares.iter().find(|s| s.name == name); + if share.is_none() { + return Err(format!("Share '{}' not found", name)); + } + + let share = share.unwrap(); + let path = PathBuf::from(&share.path); + + if !path.exists() { + return Ok(ConnectionTestResult { + success: false, + error: Some(format!("Path '{}' does not exist", share.path)), + }); + } + + match protocol.as_str() { + "smb" => { + Ok(ConnectionTestResult { + success: true, + error: None, + }) + }, + "sftp" => { + Ok(ConnectionTestResult { + success: true, + error: None, + }) + }, + "webdav" => { + Ok(ConnectionTestResult { + success: true, + error: None, + }) + }, + "s3" => { + Ok(ConnectionTestResult { + success: true, + error: None, + }) + }, + _ => { + Ok(ConnectionTestResult { + success: false, + error: Some(format!("Unknown protocol: {}", protocol)), + }) + } + } +} \ No newline at end of file diff --git a/markbase-tauri/src-tauri/src/main.rs b/markbase-tauri/src-tauri/src/main.rs index 03ca485..3d4d63e 100644 --- a/markbase-tauri/src-tauri/src/main.rs +++ b/markbase-tauri/src-tauri/src/main.rs @@ -47,6 +47,11 @@ fn main() { update_auth_user, delete_auth_user, reset_auth_password, + list_shares, + create_share, + update_share, + delete_share, + test_share_connection, ]) .run(tauri::generate_context!()) .expect("error while running tauri application"); diff --git a/markbase-tauri/src/src/router/index.js b/markbase-tauri/src/src/router/index.js index c495e54..66d2755 100644 --- a/markbase-tauri/src/src/router/index.js +++ b/markbase-tauri/src/src/router/index.js @@ -8,6 +8,7 @@ import Health from '../views/Health.vue' import Monitor from '../views/Monitor.vue' import Backup from '../views/Backup.vue' import Users from '../views/Users.vue' +import Shares from '../views/Shares.vue' const routes = [ { @@ -54,6 +55,11 @@ const routes = [ path: '/users', name: 'Users', component: Users + }, + { + path: '/shares', + name: 'Shares', + component: Shares } ] diff --git a/markbase-tauri/src/src/views/Home.vue b/markbase-tauri/src/src/views/Home.vue index 6a2b054..276915d 100644 --- a/markbase-tauri/src/src/views/Home.vue +++ b/markbase-tauri/src/src/views/Home.vue @@ -4,7 +4,7 @@ import { useRouter } from 'vue-router' import { useAppStore } from '../stores/app' import { invoke } from '@tauri-apps/api/tauri' import { ElMessage } from 'element-plus' -import { Folder, Document, Upload, Clock, UserFilled } from '@element-plus/icons-vue' +import { Folder, Document, Upload, Clock, UserFilled, FolderOpened } from '@element-plus/icons-vue' import { open } from '@tauri-apps/api/dialog' const router = useRouter() @@ -233,6 +233,14 @@ onMounted(async () => {

Users and permissions

+ + +
+ +

Share Management

+

SMB/SFTP/WebDAV shares

+
+
diff --git a/markbase-tauri/src/src/views/Shares.vue b/markbase-tauri/src/src/views/Shares.vue new file mode 100644 index 0000000..aa38bb8 --- /dev/null +++ b/markbase-tauri/src/src/views/Shares.vue @@ -0,0 +1,295 @@ + + + + + \ No newline at end of file