Skip to content

Commit b7921f5

Browse files
kelsi-bizerclaude
andauthored
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/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@bizeros/file-api",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"packageManager": "pnpm@10.33.0",
7+
"main": "src/server.js",
8+
"scripts": {
9+
"start": "node src/server.js",
10+
"test": "node --test test/*.test.js"
11+
},
12+
"dependencies": {
13+
"fastify": "5.8.2",
14+
"chokidar": "4.0.3"
15+
}
16+
}

packages/file-api/pnpm-lock.yaml

Lines changed: 370 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)