feat: Add folder structure to momentry and warren databases

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)
This commit is contained in:
Warren
2026-05-17 02:42:08 +08:00
parent 7a87988472
commit e3bf885b6b
3 changed files with 10 additions and 17 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -827,13 +827,7 @@ async fn upload_file(
hasher.update(input.as_bytes());
let hash = hasher.finalize();
let hex = format!("{:x}", hash);
let file_uuid = hex.chars().take(32).collect::<String>();
// 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::<String>());
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<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_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<serde_json::Value> {
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;