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]);