Skip to content

Commit afc0386

Browse files
authored
Merge pull request #77 from tokenhost/issue-76-netlify-foc-uploader
Add Netlify background upload scaffolding
2 parents ceb92ed + d8f0fe7 commit afc0386

15 files changed

Lines changed: 1071 additions & 5 deletions

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,18 @@ Local preview endpoints:
8686

8787
- `GET/POST /__tokenhost/relay` for sponsored local writes (anvil).
8888
- `GET/POST /__tokenhost/faucet` remains available for non-sponsored local mode.
89+
90+
## Netlify uploads
91+
92+
Token Host can now emit Netlify upload scaffolding for Filecoin Onchain Cloud:
93+
94+
- schema surface: `app.deploy.netlify.uploads`
95+
- build output includes:
96+
- `netlify.toml`
97+
- `netlify/functions/`
98+
- `NETLIFY-UPLOADS.md`
99+
100+
Runtime secrets for Netlify Functions must come from Netlify environment variables, not `netlify.toml`.
101+
102+
See:
103+
- `docs/examples-microblog-netlify-upload.md`

apps/example/microblog.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
"accentText": "blog"
1010
},
1111
"primaryCollection": "Post",
12+
"deploy": {
13+
"netlify": {
14+
"uploads": {
15+
"provider": "filecoin_onchain_cloud",
16+
"runner": "background-function"
17+
}
18+
}
19+
},
1220
"theme": {
1321
"preset": "cyber-grid"
1422
},
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Microblog Example: Netlify Background Uploads
2+
3+
This document shows how to generate the canonical microblog example so image uploads run through Netlify Background Functions and Filecoin Onchain Cloud instead of a VPS-hosted upload process.
4+
5+
Relevant files:
6+
- schema: `apps/example/microblog.schema.json`
7+
- generated Netlify artifacts: `out/microblog/netlify.toml`, `out/microblog/netlify/functions/`
8+
9+
## 1. Build the microblog app
10+
11+
```bash
12+
th build apps/example/microblog.schema.json --chain filecoin_calibration --out out/microblog
13+
```
14+
15+
Because the schema includes:
16+
17+
```json
18+
{
19+
"app": {
20+
"deploy": {
21+
"netlify": {
22+
"uploads": {
23+
"provider": "filecoin_onchain_cloud",
24+
"runner": "background-function"
25+
}
26+
}
27+
}
28+
}
29+
}
30+
```
31+
32+
the build emits:
33+
- `out/microblog/netlify.toml`
34+
- `out/microblog/netlify/functions/tokenhost-upload-start.mjs`
35+
- `out/microblog/netlify/functions/tokenhost-upload-status.mjs`
36+
- `out/microblog/netlify/functions/tokenhost-upload-worker-background.mjs`
37+
- `out/microblog/NETLIFY-UPLOADS.md`
38+
39+
The generated manifest is also wired so the browser upload client talks to:
40+
- `POST /__tokenhost/upload`
41+
- `GET /__tokenhost/upload-status?jobId=...`
42+
43+
## 2. Set Netlify environment variables
44+
45+
Set these in Netlify with **Functions** scope:
46+
47+
- `TH_UPLOAD_FOC_PRIVATE_KEY`
48+
- `TH_UPLOAD_FOC_CHAIN=314159`
49+
- `TH_UPLOAD_FOC_COPIES=1`
50+
51+
Optional:
52+
53+
- `TH_UPLOAD_FOC_COMMAND=npx -y foc-cli`
54+
- `TH_UPLOAD_FOC_WITH_CDN=true`
55+
- `TH_UPLOAD_FOC_DEBUG=true`
56+
57+
Important:
58+
- runtime secrets must come from Netlify environment variables
59+
- do not put the private key in `netlify.toml`
60+
61+
## 3. Deploy to Netlify
62+
63+
Deploy the generated build root so Netlify sees:
64+
- `ui-site/` as the publish directory
65+
- `netlify/functions/` as the functions directory
66+
67+
The generated `netlify.toml` already configures those paths and the upload redirects.
68+
69+
## 4. Expected runtime flow
70+
71+
1. Browser uploads file bytes to `POST /__tokenhost/upload`
72+
2. Start function stores the request in Netlify Blobs and returns `202` with `jobId`
73+
3. Netlify background worker runs `foc-cli upload`
74+
4. Worker stores success or failure result in Netlify Blobs
75+
5. Browser polls `/__tokenhost/upload-status?jobId=...` until complete
76+
77+
## Current status
78+
79+
This generated target is meant to remove the VPS requirement for FOC uploads.
80+
81+
What is implemented in Token Host now:
82+
- schema/build support for a Netlify upload deployment target
83+
- generated Netlify functions scaffolding
84+
- manifest/runtime wiring compatible with the existing async browser upload client
85+
86+
What still needs real-world validation:
87+
- Netlify runtime compatibility for `foc-cli`
88+
- final deploy ergonomics and any provider-specific edge cases

docs/examples-microblog-remote-upload.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ This document shows how to run the canonical microblog example against a standal
44

55
Relevant files:
66
- schema: `apps/example/microblog.schema.json`
7-
- UI overrides: `apps/example/microblog-ui/`
87
- standalone adapter: `examples/upload-adapters/foc-remote-adapter.mjs`
98

109
## 1. Start a remote upload adapter

0 commit comments

Comments
 (0)