Phase 1成果: - 数据库准备:demo.sqlite(117文件,5.07GB) - 双虚拟Tree:demo_library_zh + demo_library_en - 文件分类映射:258个节点(自动分类) Phase 2成果: - Tauri项目初始化:完整项目结构 - 7个管理模块:安装/配置/诊断/管理/健康/监控/文件浏览 - 7个Rust Commands:完整后端逻辑(约3000行) - 7个Vue页面:完整前端UI(约2000行) - Vite build修复:Rolldown外部化配置成功 - 前端构建成功:dist目录生成 总体进度:90%完成(约5000行代码)
125 lines
3.3 KiB
Rust
125 lines
3.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct AppConfig {
|
|
pub database: DatabaseConfig,
|
|
pub web_server: WebServerConfig,
|
|
pub ssh: SSHConfig,
|
|
pub nfs: NFSConfig,
|
|
pub smb: SMBConfig,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct DatabaseConfig {
|
|
pub path: String,
|
|
pub max_connections: u32,
|
|
pub auto_backup: bool,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct WebServerConfig {
|
|
pub port: u32,
|
|
pub enable_ssl: bool,
|
|
pub ssl_cert_path: Option<String>,
|
|
pub enable_auth: bool,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct SSHConfig {
|
|
pub enabled: bool,
|
|
pub port: u32,
|
|
pub enable_sftp: bool,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct NFSConfig {
|
|
pub enabled: bool,
|
|
pub mount_point: String,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
|
pub struct SMBConfig {
|
|
pub enabled: bool,
|
|
pub share_name: String,
|
|
}
|
|
|
|
impl Default for AppConfig {
|
|
fn default() -> Self {
|
|
AppConfig {
|
|
database: DatabaseConfig {
|
|
path: "data/users".to_string(),
|
|
max_connections: 10,
|
|
auto_backup: true,
|
|
},
|
|
web_server: WebServerConfig {
|
|
port: 11438,
|
|
enable_ssl: false,
|
|
ssl_cert_path: None,
|
|
enable_auth: false,
|
|
},
|
|
ssh: SSHConfig {
|
|
enabled: false,
|
|
port: 2222,
|
|
enable_sftp: false,
|
|
},
|
|
nfs: NFSConfig {
|
|
enabled: false,
|
|
mount_point: "/mnt/markbase".to_string(),
|
|
},
|
|
smb: SMBConfig {
|
|
enabled: false,
|
|
share_name: "markbase".to_string(),
|
|
},
|
|
}
|
|
}
|
|
}
|
|
|
|
fn get_config_path() -> PathBuf {
|
|
PathBuf::from("config/markbase.json")
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn load_config() -> Result<AppConfig, String> {
|
|
let config_path = get_config_path();
|
|
|
|
if !config_path.exists() {
|
|
let default_config = AppConfig::default();
|
|
save_config(default_config.clone()).await?;
|
|
return Ok(default_config);
|
|
}
|
|
|
|
let config_str = fs::read_to_string(&config_path)
|
|
.map_err(|e| format!("Failed to read config file: {}", e))?;
|
|
|
|
let config: AppConfig = serde_json::from_str(&config_str)
|
|
.map_err(|e| format!("Failed to parse config file: {}", e))?;
|
|
|
|
Ok(config)
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn save_config(config: AppConfig) -> Result<(), String> {
|
|
let config_path = get_config_path();
|
|
|
|
if let Some(parent) = config_path.parent() {
|
|
fs::create_dir_all(parent)
|
|
.map_err(|e| format!("Failed to create config directory: {}", e))?;
|
|
}
|
|
|
|
let config_str = serde_json::to_string_pretty(&config)
|
|
.map_err(|e| format!("Failed to serialize config: {}", e))?;
|
|
|
|
fs::write(&config_path, config_str)
|
|
.map_err(|e| format!("Failed to write config file: {}", e))?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[tauri::command]
|
|
pub async fn reset_config() -> Result<AppConfig, String> {
|
|
let default_config = AppConfig::default();
|
|
save_config(default_config.clone()).await?;
|
|
Ok(default_config)
|
|
} |