Skip to content

Latest commit

 

History

History
124 lines (93 loc) · 2.84 KB

File metadata and controls

124 lines (93 loc) · 2.84 KB

Demo2APK API 文档

基础信息

  • Base URL: http://localhost:3000
  • Content-Type: multipart/form-data (上传) / application/json (响应)

端点概览

方法 端点 描述
GET /health 服务健康检查
POST /api/build/html 上传 HTML 文件构建 APK
POST /api/build/zip 上传 ZIP 项目构建 APK
GET /api/build/:taskId/status 查询任务状态
GET /api/build/:taskId/download 下载构建完成的 APK
DELETE /api/build/:taskId 取消任务并清理文件

可选能力:当服务端开启 PWA_ENABLED=true 时,构建请求可携带 publishPwa=true,Worker 会额外导出一个可安装的 PWA 站点(静态文件),用于分享/预览。

详细说明

1. 健康检查

GET /health

响应:

{
  "status": "ok",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

2. HTML 构建

POST /api/build/html

参数:

字段 类型 必填 说明
file File HTML 文件 (.html/.htm)
appName string 应用名称 (默认 "MyVibeApp")
appId string 包名 (自动生成)
publishPwa string 是否额外导出 PWA (true/false)

示例:

curl -X POST http://localhost:3000/api/build/html \
  -F "file=@mypage.html" \
  -F "appName=MyApp" \
  -F "publishPwa=true"

3. ZIP/React 构建

POST /api/build/zip

参数:

字段 类型 必填 说明
file File 项目 ZIP 包
appName string 应用名称 (默认 "MyReactApp")
appId string 包名 (默认 "com.demo2apk.reactapp")
publishPwa string 是否额外导出 PWA (true/false)

支持项目:

  • Vite + React
  • Create React App
  • Next.js (静态导出)

4. 查询状态

GET /api/build/:taskId/status

状态值:

  • pending: 等待中
  • active: 构建中
  • completed: 完成
  • failed: 失败

响应示例:

{
  "taskId": "abc123xyz",
  "status": "active",
  "progress": {
    "message": "Building APK...",
    "percent": 70
  },
  "pwa": {
    "siteId": "myapp-1a2b3c4d",
    "url": "https://myapp-1a2b3c4d.pwa.example.com/"
  }
}

5. 下载 APK

GET /api/build/:taskId/download

返回 APK 文件流。

6. 删除任务

DELETE /api/build/:taskId

清理任务记录和相关临时文件。