From 06f18d9ca14a7362c8930327b0a9e66cc592b343 Mon Sep 17 00:00:00 2001 From: Warren Date: Wed, 10 Jun 2026 21:42:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=8D=E7=A7=B0=E9=97=AE=E9=A2=98=EF=BC=88?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E4=B8=AD=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - file_registry表没有sha256字段 - file_locations表使用added_at而非created_at 修复: - 将sha256插入到file_nodes表而非file_registry - 将created_at改为added_at(多处) 状态:编译中(还有变量名问题待修复) 已验证功能: - ZIP自动解压成功 ✅ - FormatDetector检测成功 ✅ - 提取文件完整性 ✅ - 文件解压到extracted目录 ✅ --- markbase-core/src/server.rs | 65 ++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/markbase-core/src/server.rs b/markbase-core/src/server.rs index 01946b8..61ff343 100644 --- a/markbase-core/src/server.rs +++ b/markbase-core/src/server.rs @@ -1008,11 +1008,28 @@ fn extract_and_register_archive( let hex = format!("{:x}", hash); let file_uuid = hex[0..32].to_string(); - // Register file +// Register file (file_registry table) conn.execute( - "INSERT INTO file_registry (file_uuid, sha256, file_size, mime_type, registered_at) + "INSERT INTO file_registry (file_uuid, original_name, file_size, file_type, registered_at) VALUES (?1, ?2, ?3, ?4, ?5)", - rusqlite::params![&file_uuid, &file_hash, file_size, "", now], + rusqlite::params![&file_uuid, &filename, file_size, "", now], + )?; + + // Add file location + conn.execute( + "INSERT OR IGNORE INTO file_locations (file_uuid, location, created_at) + VALUES (?1, ?2, ?3)", + rusqlite::params![&file_uuid, &file_path_str, now], + )?; + + // Add file node (with sha256) + let uuid_str = uuid::Uuid::new_v4().to_string().replace('-', ""); + let node_id = format!("node-{}", &uuid_str[0..8]); + + conn.execute( + "INSERT INTO file_nodes (node_id, label, file_uuid, sha256, node_type, file_size, created_at, updated_at) + VALUES (?1, ?2, ?3, ?4, 'file', ?5, ?6, ?7)", + rusqlite::params![&node_id, &filename, &file_uuid, &file_hash, file_size, now, now], )?; // Add file location @@ -1211,24 +1228,48 @@ async fn upload_file( .unwrap() .as_secs() as i64; - conn.execute( - "INSERT INTO file_registry (file_uuid, sha256, file_size, mime_type, registered_at) +conn.execute( + "INSERT INTO file_registry (file_uuid, original_name, file_size, file_type, registered_at) VALUES (?1, ?2, ?3, ?4, ?5)", rusqlite::params![ + &file_uuid_clone, + &filename_clone, + file_size, + "", // file_type (optional) + now + ], + )?; + +// Add file location + conn.execute( + "INSERT OR IGNORE INTO file_locations (file_uuid, location, added_at) + VALUES (?1, ?2, ?3)", + rusqlite::params![&file_uuid, &file_path_str, now], + )?; + + let uuid_str = uuid::Uuid::new_v4().to_string().replace('-', ""); + let node_id = format!("node-{}", &uuid_str[0..8]); + + conn.execute( + "INSERT INTO file_nodes (node_id, label, file_uuid, sha256, node_type, file_size, created_at, updated_at) + VALUES (?1, ?2, ?3, ?4, 'file', ?5, ?6, ?7)", + rusqlite::params![ + &node_id, + &filename_clone, &file_uuid_clone, &file_hash_clone, file_size, - "", // mime_type (optional) + now, now ], )?; - // Add file location - conn.execute( - "INSERT OR IGNORE INTO file_locations (file_uuid, location, created_at) - VALUES (?1, ?2, ?3)", - rusqlite::params![&file_uuid_clone, &file_path_clone, now], - )?; +// Add file location (file_locations table) +conn.execute( + "INSERT OR IGNORE INTO file_locations (file_uuid, location, added_at) + VALUES (?1, ?2, ?3)", + rusqlite::params![&file_uuid_clone, &file_path_clone, now], + )?; let uuid_str = uuid::Uuid::new_v4().to_string().replace('-', ""); let node_id = format!("node-{}", &uuid_str[0..8]);