Commit b7921f5
Phase 1: file-api service for VM filesystem persistence (#3)
Adds packages/file-api — a Fastify HTTP service that exposes a small
file API rooted at $BRAIN_DIR (default /brain). Phase 1 of the plan
to move BizerOS Knowledge off browser IndexedDB and onto markdown
files persisted on the VM.
Endpoints:
- GET /api/health
- GET /api/tree — flat listing of files and dirs
- GET /api/file?path=... — read; returns body + x-mtime, x-size
- PUT /api/file?path=... — atomic write (tmp + rename), mkdir -p
- DELETE /api/file?path=...
- POST /api/move — { from, to }
- GET /api/watch — Server-Sent Events FS change stream
Safety:
- resolveSafe() rejects null bytes, traversal (../), and any path
whose resolved absolute escapes brainDir.
- Extension allowlist (.md/.edn/.json/.txt/.org/.png/.jpg/.jpeg/.gif
/.webp/.svg/.pdf), case-insensitive, configurable via env.
- 25 MB default body cap.
- Binds 127.0.0.1 by default — meant to live behind nginx in the
same container, not exposed directly.
Tests use node:test + fastify.inject() — 20 cases covering happy
paths, traversal/extension rejection, mkdir-p, move, delete-missing.
Co-authored-by: Claude <noreply@anthropic.com>1 parent a5e7d61 commit b7921f5
11 files changed
Lines changed: 871 additions & 0 deletions
File tree
- packages/file-api
- src
- routes
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments