Phase 2.7.3完成:文件上传功能实现
Some checks failed
Test / test (push) Has been cancelled
Test / build (push) Has been cancelled

功能:
- Tauri dialog API集成(文件选择对话框)
- upload_file命令完整实现(文件复制 + 数据库注册)
- 上传按钮UI(带loading状态)
- 上传完成后自动刷新文件树

技术:
- 添加uuid依赖(UUID v4生成)
- Rust: std::fs文件复制 + rusqlite数据库注册
- Vue: @tauri-apps/api/dialog集成
- Vite: 修复dialog API外部化配置

状态:Phase 2完成100%
This commit is contained in:
Warren
2026-06-13 16:09:58 +08:00
parent d7afd109b0
commit ceadeef329
5 changed files with 109 additions and 11 deletions

View File

@@ -1993,6 +1993,7 @@ dependencies = [
"tauri-build",
"thiserror",
"tokio",
"uuid",
]
[[package]]

View File

@@ -25,6 +25,7 @@ chrono = { version = "0.4", features = ["serde"] }
anyhow = "1.0"
thiserror = "1.0"
rusqlite = { version = "0.30", features = ["bundled"] }
uuid = { version = "1.0", features = ["v4"] }
[features]
custom-protocol = [ "tauri/custom-protocol" ]

View File

@@ -1,7 +1,5 @@
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tauri::State;
use std::sync::Mutex;
use std::path::{Path, PathBuf};
use rusqlite::Connection;
#[derive(Debug, Serialize, Deserialize, Clone)]
@@ -116,10 +114,42 @@ pub async fn upload_file(
target_path: String,
tree_type: String,
) -> Result<FileUploadResult, String> {
use std::fs;
use uuid::Uuid;
let demo_dir = "/Users/accusys/momentry/var/sftpgo/data/demo";
let target_file = PathBuf::from(demo_dir).join(&target_path);
if !Path::new(&source_path).exists() {
return Err(format!("Source file not found: {}", source_path));
}
fs::copy(&source_path, &target_file)
.map_err(|e| format!("Failed to copy file: {}", e))?;
let db_path = PathBuf::from("data/users")
.join(format!("{}.sqlite", user_id));
let conn = Connection::open(&db_path)
.map_err(|e| format!("Failed to open database: {}", e))?;
let file_uuid = Uuid::new_v4().to_string();
let file_name = Path::new(&target_path)
.file_name()
.and_then(|n| n.to_str())
.unwrap_or("unknown")
.to_string();
conn.execute(
"INSERT INTO file_registry (file_uuid, original_name, file_path, file_size, registered_at, last_seen_at, status)
VALUES (?1, ?2, ?3, ?4, datetime('now'), datetime('now'), 'active')",
rusqlite::params![&file_uuid, &file_name, target_file.to_string_lossy().to_string(), fs::metadata(&target_file).map(|m| m.len() as i64).unwrap_or(0)]
).map_err(|e| format!("Failed to register file: {}", e))?;
Ok(FileUploadResult {
success: true,
message: "File uploaded successfully".to_string(),
file_id: Some("file-001".to_string()),
message: format!("File uploaded to: {}", target_path),
file_id: Some(file_uuid),
})
}