Commit Graph

5 Commits

Author SHA1 Message Date
Warren
89aa4989da feat: Add file_locations to scan and fix file info API
Problem:
- Files could not be clicked (error: no location)
- get_file_info used hardcoded demo database
- file_locations table was empty

Solution:
1. Scan now inserts file_locations records
   - file_uuid = node_id (temporary)
   - location = file path (from aliases)
   - label = origin

2. Modified API routes to include user_id
   - /api/v2/files/:user_id/:file_uuid/info
   - /api/v2/files/:user_id/:file_uuid/stream

3. Modified showDetail() to use tree_user from localStorage

Result:
- file_locations: 11857 records 
- Files can be clicked 
- API uses correct user database 

Files:
- src/scan.rs (insert file_locations)
- src/server.rs (user_id parameter)
- src/page.html (showDetail with user_id)
2026-05-17 04:29:46 +08:00
Warren
5dbe69d08f fix: Set temporary file_uuid for files without SHA256
Problem:
- File nodes had null file_uuid
- Clicking files in UI showed nothing (showDetail() returned early)
- User could not view file details

Solution:
- Set file_uuid to node_id (temporary value) during scan
- Even without SHA256 hash, files can be clicked
- file_uuid will be updated when hash is calculated

Result:
- All files have file_uuid 
- Clicking files shows detail panel 
- UI fully functional 

Files:
- src/scan.rs (file_uuid = node_id)
2026-05-17 04:07:32 +08:00
Warren
d783fdc397 feat: Add children_json update to scan system
Problem:
- Home folder could not expand (children_json was empty)
- UI tree view showed flat structure

Solution:
- Add step [5/5] to update children_json for all folders
- Use SQL: json_group_array(node_id) to collect child IDs
- Update 802 folders after node insertion

Performance:
- Children JSON update: 1.55s (74% of total time)
- Total scan time: 2.08s (vs 0.89s without children)

Result:
- Home folder has 805 children 
- Tree structure fully functional 
- API returns correct children array 

Files:
- src/scan.rs (added children_json update step)
2026-05-17 03:35:35 +08:00
Warren
86fa66bb42 fix: Add parent_id to all nodes in scan system
Problem:
- All nodes (files and folders) had NULL parent_id
- Tree structure was flat (no hierarchy)
- Could not display proper folder tree

Solution:
- Add Home folder as root node
- Map folder paths to node_ids (folder_id_map)
- Set parent_id for all folders (point to parent folder's node_id)
- Set parent_id for all files (point to containing folder's node_id)
- Root directory files/folders point to Home folder

Result:
- Folders: 802 (801 + Home root)
- Files: 11857
- Total nodes: 12659
- Nodes with parent_id: 12658 (100%)
- Tree structure fully functional 

Files:
- src/scan.rs (fixed parent_id logic)
2026-05-17 03:26:15 +08:00
Warren
05f89ea1ac feat: Add file scan and async hash system
Features:
1. scan command - Fast import without hash (skip_hash=true)
   - Scans directory structure
   - Generates deterministic UUIDs (SHA256(path|name|mac|mtime))
   - Stores full path in aliases.json
   - Inserts nodes in batches
   - Performance: 14243 nodes/sec (11857 files in 0.89s)

2. hash command - Async hash calculation
   - Multi-threaded (default: 4 threads)
   - Reads paths from aliases.json
   - Updates database with SHA256 hashes
   - Performance: 28 files/sec (11857 files in 417.58s)

Design:
- Import first, hash later (user can view tree immediately)
- Hash runs in background (non-blocking)
- Path stored in aliases.json (temporary solution)
- Deterministic UUIDs (same file = same UUID)

Performance breakdown:
- Scanning: 0.10s (11%)
- ID generation: 0.57s (64%)
- DB insertion: 0.21s (24%)
- Hash: 417.58s (async, background)

Files:
- src/scan.rs (new, 499 lines)
- src/main.rs (scan/hash commands)
- src/lib.rs (scan module)

Test result:
- warren user: 12658 nodes imported
- 11857 hashes calculated successfully
2026-05-17 03:20:35 +08:00