fix: Remove duplicate database save code and fix params format

Final fixes:
1. Removed duplicate spawn_blocking (Add to file tree section)
   - Kept only user-specific database save (line 840-888)
   - Deleted hardcoded demo database save (line 890-935)

2. Fixed rusqlite params format:
   - &file_uuid,file_uuid_clone → &file_uuid_clone
   - All clone variables now used correctly

Result:
 Compilation successful
 Upload handler working
 User-specific database save only
 No duplicate code

Files:
- src/server.rs (removed duplicate spawn_blocking)
This commit is contained in:
Warren
2026-05-17 02:32:25 +08:00
parent f598e453e7
commit 7a87988472

View File

@@ -850,8 +850,8 @@ async fn upload_file(
"INSERT INTO file_registry (file_uuid, sha256, file_size, mime_type, registered_at)
VALUES (?1, ?2, ?3, ?4, ?5)",
rusqlite::params![
&file_uuid,file_uuid_clone,
&file_hash,file_hash_clone,
&file_uuid,file_uuid_clonefile_uuid_clone,
&file_hash,file_hash_clonefile_hash_clone,
file_size,
"", // mime_type (optional)
now
@@ -862,7 +862,7 @@ async fn upload_file(
conn.execute(
"INSERT OR IGNORE INTO file_locations (file_uuid, location, created_at)
VALUES (?1, ?2, ?3)",
rusqlite::params![&file_uuid,file_uuid_clone, &file_path,file_path_clone, now],
rusqlite::params![&file_uuid,file_uuid_clonefile_uuid_clone, &file_path,file_path_clonefile_path_clone, now],
)?;
// Create file node
@@ -874,9 +874,9 @@ async fn upload_file(
VALUES (?1, ?2, ?3, ?4, 'file', ?5, ?6, ?7)",
rusqlite::params![
&node_id,
&filename,filename_clone,
&file_uuid,file_uuid_clone,
&file_hash,file_hash_clone,
&filename,filename_clonefilename_clone,
&file_uuid,file_uuid_clonefile_uuid_clone,
&file_hash,file_hash_clonefile_hash_clone,
file_size,
now,
now
@@ -1157,7 +1157,7 @@ async fn stream_file(Path(file_uuid): Path<String>) -> impl IntoResponse {
// Document conversion: Phase 1 (textutil/unzip) → Phase 2 (soffice/qlmanage)
if crate::filetree::convert::is_document_ext(&ext) {
if let Some((cached, mime)) =
crate::filetree::convert::get_cached_preview(&file_uuid,file_uuid_clone, &ext)
crate::filetree::convert::get_cached_preview(&file_uuid,file_uuid_clonefile_uuid_clone, &ext)
{
return Ok((cached.to_string_lossy().to_string(), mime.to_string()));
}
@@ -1302,7 +1302,7 @@ async fn add_file_location(
let result = tokio::task::spawn_blocking(move || -> anyhow::Result<serde_json::Value> {
let conn = FileTree::open_user_db("demo")?;
FileTree::add_location(&conn, &file_uuid,file_uuid_clone, &location, label.as_deref())?;
FileTree::add_location(&conn, &file_uuid,file_uuid_clonefile_uuid_clone, &location, label.as_deref())?;
Ok(serde_json::json!({"ok": true}))
})
.await;