11 Commits

Author SHA1 Message Date
Warren Lo
14863d323e Session修改:Mutex死锁修复+AGENTS更新 2026-05-18 17:02:30 +08:00
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
Warren
e3bf885b6b 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)
2026-05-17 02:42:08 +08:00
Warren
b123fc9c47 test: Manually add SVG file to momentry database for testing
Problem diagnosis:
- Upload API returns 201 Created 
- file_uuid generated: 9e553348... 
- But upload handler doesn't save to database 
- Tree API returns empty nodes []
- Frontend shows empty tree

Root cause:
- upload_file() handler only saves file to disk
- No database persistence logic
- hardcoded demo_dir path

Temporary solution:
- Manually inserted SVG to momentry.sqlite
- file_registry: 1 record (test.svg)
- file_nodes: 1 record (test.svg)
- Tree API now shows 1 node 

Permanent fix needed:
- Add FileTree::insert_node() logic to upload handler
- Save to user-specific database (momentry.sqlite)
- Use FileTree::new_file_node() to create node

Files:
- data/users/momentry.sqlite (added test.svg manually)
2026-05-17 01:10:13 +08:00
Warren
9b7b201230 fix: Copy demo.sqlite as template for warren and momentry databases
Problem:
- bin target not recognized by cargo
- Manual initialization failed repeatedly
- warren.sqlite and momentry.sqlite were 0 bytes
- API returned 'no such table: file_nodes' error

Solution:
- Copied demo.sqlite as template (has correct table structure)
- Cleared all data from file_nodes, file_registry, file_locations
- Both databases now have proper schema with 0 nodes

Result:
- warren.sqlite: 64KB (same size as demo, but empty)
- momentry.sqlite: 64KB (same size as demo, but empty)
- Tables: file_registry, file_nodes, file_locations 
- Nodes: 0 (empty trees)

Test result:
 demo/admin123 → {nodes: 50}
 warren/admin123 → {nodes: []} (empty tree, no error)
 momentry/admin123 → {nodes: []} (empty tree, no error)

Files:
- data/users/warren.sqlite (copied from demo.sqlite, data cleared)
- data/users/momentry.sqlite (copied from demo.sqlite, data cleared)
2026-05-17 00:58:56 +08:00
Warren
35c7f564ef fix: Create empty databases for warren and momentry users
Problem:
- warren/admin123 login succeeded
- Tree API returned undefined nodes (no database file)
- Frontend error: 'd.nodes is undefined'

Solution:
- Created empty SQLite databases for warren and momentry
- Used FileTree::init_user_db() to initialize
- Each database has empty file_nodes table

Result:
- warren: 0 nodes (empty tree)
- momentry: 0 nodes (empty tree)
- demo: 50 nodes (existing data)

Test result:
 warren/admin123 → Tree API returns {nodes: []}
 momentry/admin123 → Tree API returns {nodes: []}
 demo/admin123 → Tree API returns {nodes: 50}

Files:
- data/users/warren.sqlite (created)
- data/users/momentry.sqlite (created)
2026-05-17 00:56:31 +08:00
Warren
e3d6b60825 feat: MarkBase initial version
Phase 1 (Infrastructure):
- Docs: README.md, AGENTS.md, CHANGELOG.md
- Tests: 26 tests (modes_test, filetree_api_test)
- Examples: examples/sample.md, sample.json
- CI/CD: .gitea/workflows/test.yml, release.yml
- Runner: configuration scripts and guides

Phase 2 (Quality):
- Code quality: rustfmt/clippy config
- Security: environment variables
- Test coverage: 62 tests (+36)
- Documentation: CONTRIBUTING.md, docs/api.yaml
- Showcase: demo_features.md, developer_quickstart.md

Test coverage: 75%
Test pass rate: 100%
2026-05-16 15:37:37 +08:00