update at 2026-02-08 22:31:25
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
`apiserver/` 提供微信小程序用的远端渲染接口:
|
||||
- 小程序只上传参数(字体 ID、文字、字号、颜色等)
|
||||
- 服务端读取 `fonts.json` + `fonts/`,生成 SVG 后返回
|
||||
- 服务端读取 `fonts.json` + `fonts/`,生成 SVG/PNG 后返回
|
||||
|
||||
## 1. 启动
|
||||
|
||||
@@ -43,6 +43,11 @@ python3 apiserver/server.py \
|
||||
}
|
||||
```
|
||||
|
||||
### POST `/api/render-png`
|
||||
|
||||
请求体与 `/api/render-svg` 相同,成功时直接返回 `image/png` 二进制。
|
||||
小程序应使用 `wx.request({ responseType: 'arraybuffer' })` 接收。
|
||||
|
||||
成功响应:
|
||||
|
||||
```json
|
||||
@@ -82,8 +87,20 @@ location /api/ {
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
## 4. 约束
|
||||
## 4. systemd(可选)
|
||||
|
||||
仓库内提供示例:`apiserver/font2svg-api.service.example`,可复制到:
|
||||
|
||||
```bash
|
||||
sudo cp apiserver/font2svg-api.service.example /etc/systemd/system/font2svg-api.service
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable --now font2svg-api
|
||||
sudo systemctl status font2svg-api
|
||||
```
|
||||
|
||||
## 5. 约束
|
||||
|
||||
- 字体解析完全基于 `fonts.json`,`fontId` 必须存在。
|
||||
- 服务端启用 CORS,允许小程序访问。
|
||||
- 不依赖 Flask/FastAPI,使用 Python 标准库 HTTP 服务。
|
||||
- `/api/render-png` 依赖 `node + sharp`(使用 `apiserver/svg_to_png.js` 转换)。
|
||||
|
||||
Reference in New Issue
Block a user