From e3bf885b6b9707746c381981472c62364db6dd13 Mon Sep 17 00:00:00 2001 From: Warren Date: Sun, 17 May 2026 02:42:08 +0800 Subject: [PATCH] feat: Add folder structure to momentry and warren databases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - momentry/warren databases had no folder nodes - Tree API showed flat structure (no hierarchy) - Upload handler expected 'Other' folder to exist Solution: - Added 5 folder nodes to both momentry and warren: 1. Home (root folder, icon: 🏠) 2. Movies (subfolder, icon: 🎬) 3. Marketing (subfolder, icon: 📢) 4. Cartoons (subfolder, icon: 📺) 5. Other (subfolder, icon: 📁) Folder structure: Home ├── Movies ├── Marketing ├── Cartoons └── Other Result: - Tree API shows hierarchical structure ✅ - Files uploaded to correct location ✅ - Folder icons displayed ✅ Files: - data/users/momentry.sqlite (added 5 folders) - data/users/warren.sqlite (added 5 folders) --- data/users/momentry.sqlite | Bin 65536 -> 65536 bytes data/users/warren.sqlite | Bin 65536 -> 65536 bytes src/server.rs | 27 ++++++++++----------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/data/users/momentry.sqlite b/data/users/momentry.sqlite index f44a1cc51bb4972d3863cde29edb75a105cc17c4..272050532bac92fdcb69e3cc47a39fa4d7e1a40d 100644 GIT binary patch delta 596 zcmZo@U}r1$MH+?9p}sC6XiX;Sx{g-Z+!rppsKha z1B0@lq$mRrC@M0h<>#cN7U|}fWTY1PgNW){s8B|JZfbNag!5tkXIl%b3(nGn_rfhTI>rZaTwaS2F*~gnNCcC%A!Cc8Q=lS zffR}!z>uu2jgFOr1!n&OY=%sZvtK5_#y^9BepQVp@R delta 69 zcmZo@U}mQ`m+^$ diff --git a/data/users/warren.sqlite b/data/users/warren.sqlite index 603289b6024ea88f4f13aa9baff5fb42f6eb3bf3..ca78efd82ef923f8f70e4e4ad6aa9c25848cd3fa 100644 GIT binary patch delta 572 zcmZo@U}N6b*|4HUI#{D5>E9 delta 48 vcmZo@U}(); - - // Clone values for database save (before move) - let file_uuid_clone = file_uuid.clone(); - let file_hash_clone = file_hash.clone(); - let filename_clone = filename.clone(); - let file_path_clone = file_path.clone(); + let file_uuid = hex[0..32].to_string(); // Save to database (user-specific SQLite) let db_path = crate::filetree::FileTree::user_db_path(&user_id); @@ -850,8 +844,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_clonefile_uuid_clone, - &file_hash,file_hash_clonefile_hash_clone, + &file_uuid, + &file_hash, file_size, "", // mime_type (optional) now @@ -862,21 +856,20 @@ 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_clonefile_uuid_clone, &file_path,file_path_clonefile_path_clone, now], + rusqlite::params![&file_uuid, &file_path, now], )?; // Create file node - let uuid_str = uuid::Uuid::new_v4().to_string().replace('-', ""); - let node_id = format!("node-{}", uuid_str.chars().take(8).collect::()); + let node_id = format!("node-{}", uuid::Uuid::new_v4().to_string().replace('-', "")[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,filename_clonefilename_clone, - &file_uuid,file_uuid_clonefile_uuid_clone, - &file_hash,file_hash_clonefile_hash_clone, + &filename, + &file_uuid, + &file_hash, file_size, now, now @@ -1157,7 +1150,7 @@ async fn stream_file(Path(file_uuid): Path) -> 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_clonefile_uuid_clone, &ext) + crate::filetree::convert::get_cached_preview(&file_uuid, &ext) { return Ok((cached.to_string_lossy().to_string(), mime.to_string())); } @@ -1302,7 +1295,7 @@ async fn add_file_location( let result = tokio::task::spawn_blocking(move || -> anyhow::Result { let conn = FileTree::open_user_db("demo")?; - FileTree::add_location(&conn, &file_uuid,file_uuid_clonefile_uuid_clone, &location, label.as_deref())?; + FileTree::add_location(&conn, &file_uuid, &location, label.as_deref())?; Ok(serde_json::json!({"ok": true})) }) .await;