项目文件夹

0
yf 44fa265a3e Restore 512MiB static big.bin download at top
- buildCommand regenerates public/assets/big.bin (512MiB) at build time
- gitignore the generated blob
- add a download card at the top of the page, above status/upload
2026-09-18 17:07:13 +08:00
2026-09-18 16:32:59 +08:00

wehub-cloud-tpl-static-site-function

WeHub Cloud 模板:静态站 + /api/cloud/* 函数,带上传 / 下载功能,文件落对象存储,元信息存 PostgreSQL

资源

资源 说明
public/ 静态前端,占根路由 /type=staticoutputDirectory=public
functions/api/ HTTP 函数,入口 index.handler,绑 /api/cloud/*
Postgres 控制台绑定后注入 DATABASE_URL,存元信息
对象存储 控制台绑定后注入 S3_*,存文件本体

接口

方法 路径 说明
GET /api/cloud/health 绑定状态
POST /api/cloud/uploads 申请上传:返回 id + presigned PUT URL,DB 写一条 pending 元信息
POST /api/cloud/uploads/:id/confirm 上传完成后回填 size / status=ready
GET /api/cloud/uploads 列出元信息
GET /api/cloud/uploads/:id 取单条 + presigned GET 下载 URL
DELETE /api/cloud/uploads/:id 删对象 + 删元信息

流程

  1. 前端选文件 → POST /api/cloud/uploads → 拿到 upload_url + id
  2. 前端 PUT upload_url 直传对象存储(不经过函数)
  3. 前端 POST /api/cloud/uploads/:id/confirm → 后端把元信息置为 ready
  4. 下载:GET /api/cloud/uploads/:id → 拿 presigned GET URL → 浏览器跳转

部署

  1. 仓库根有 wehub.jsonfunctions/api 目录存在。
  2. 控制台给 Preview 绑定 Postgres对象存储,重新部署后函数才能拿到 DATABASE_URL / S3_*
  3. 部署后访问 Preview 根路径即可。

本地

cd functions/api && npm install
# 需要本地 PG / S3 兼容服务,并设置 DATABASE_URL / S3_* 环境变量后才能跑通上传下载