use markbase_core::vfs::{ VfsBackend, local_fs::LocalFs, VfsSnapshotInfo, }; use std::path::PathBuf; use serde::{Serialize, Deserialize}; #[derive(Debug, Serialize, Deserialize)] pub struct SnapshotInfo { pub name: String, pub created: u64, pub size: u64, pub read_only: bool, } impl From for SnapshotInfo { fn from(info: VfsSnapshotInfo) -> Self { Self { name: info.name, created: info.created.duration_since(std::time::SystemTime::UNIX_EPOCH) .map(|d| d.as_secs()) .unwrap_or(0), size: info.size, read_only: info.read_only, } } } #[derive(Debug, Serialize, Deserialize)] pub struct StorageStatsResponse { pub total_size: u64, pub used_size: u64, pub free_size: u64, pub dedup_ratio: f64, pub compression_ratio: f64, } #[derive(Debug, Serialize, Deserialize)] pub struct BackupStatsResponse { pub enabled: bool, pub backup_count: usize, pub last_backup: Option, pub next_backup: Option, pub interval_hours: u64, pub max_snapshots: usize, } #[derive(Debug, Serialize, Deserialize)] pub struct BackupConfigResponse { pub enabled: bool, pub interval_hours: u64, pub max_snapshots: usize, pub auto_cleanup: bool, } #[tauri::command] pub async fn get_storage_stats(root_path: String) -> Result { let backend = LocalFs::new(); let path = PathBuf::from(root_path); let stat = backend.stat(&path).map_err(|e| e.to_string())?; Ok(StorageStatsResponse { total_size: stat.size, used_size: stat.size / 2, free_size: stat.size / 2, dedup_ratio: 1.0, compression_ratio: 1.0, }) } #[tauri::command] pub async fn list_snapshots(root_path: String) -> Result, String> { let backend = LocalFs::new(); let path = PathBuf::from(root_path); let snapshots = backend.list_snapshots(&path) .map_err(|e| e.to_string())?; Ok(snapshots) } #[tauri::command] pub async fn create_snapshot(root_path: String, snapshot_name: String) -> Result<(), String> { let backend = LocalFs::new(); let path = PathBuf::from(root_path); backend.create_snapshot(&path, &snapshot_name) .map_err(|e| e.to_string())?; Ok(()) } #[tauri::command] pub async fn delete_snapshot(root_path: String, snapshot_name: String) -> Result<(), String> { let backend = LocalFs::new(); let path = PathBuf::from(root_path); backend.delete_snapshot(&path, &snapshot_name) .map_err(|e| e.to_string())?; Ok(()) } #[tauri::command] pub async fn restore_snapshot(root_path: String, snapshot_name: String) -> Result<(), String> { let backend = LocalFs::new(); let path = PathBuf::from(root_path); backend.restore_snapshot(&path, &snapshot_name) .map_err(|e| e.to_string())?; Ok(()) } #[tauri::command] pub async fn get_backup_stats() -> Result { Ok(BackupStatsResponse { enabled: false, backup_count: 0, last_backup: None, next_backup: None, interval_hours: 24, max_snapshots: 7, }) } #[tauri::command] pub async fn get_backup_config() -> Result { Ok(BackupConfigResponse { enabled: false, interval_hours: 24, max_snapshots: 7, auto_cleanup: true, }) } #[tauri::command] pub async fn set_backup_config(config: BackupConfigResponse) -> Result<(), String> { Ok(()) } #[tauri::command] pub async fn run_backup() -> Result { Ok("snap_backup".to_string()) }