Skip to content

feat(api): 空间导出/导入·后端三端点:建空间 + 文件读回引用授权 + 文档同步 - #324

Merged
todosdev[bot] merged 2 commits into
mainfrom
tds/conv-01a22183-1400-7e8b-9504-b11a6e9aee68
Nov 28, 2026
Merged

todosdev[bot] merged 2 commits into
mainfrom
tds/conv-01a22183-1400-7e8b-9504-b11a6e9aee68

Conversation

@mapxn

@mapxn mapxn commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 新增 POST /api/write/spaces 端点,支持无范围限制(spaceIds === null)的全局 write 令牌创建空间并自动绑定创建者为 admin,对受限令牌严格响应 403。
  • 修正 GET /api/read/files/:key 文件读回授权逻辑,实现「引用授权」与「上传者授权」双并列判定,根据令牌可读空间收窄检索候选集,彻底杜绝全表扫描。
  • 同步更新 OpenAPI 规范、API 契约文档及 Agent 接入指南(新增空间导出/导入轻端点组装协议),并通过构建脚本重新编译内置模板常量。

Changes

  • 核心空间管理:
    • space-create.ts:抽取统一建空间核心例程 createSpace,统一处理 slug 派生与自增冲突解决、落库及空间 admin 成员关系绑定。
    • spaces.ts:重构会话建空间端点复用 createSpace 核心例程。
  • 写端点与读端点:
    • write.ts:新增 POST /api/write/spaces,校验全局 write 令牌,返回 201 { id, slug, title }。
    • read.ts:重构 GET /api/read/files/:key,引入 hasReferencedPageReadAccess 辅助函数支持页面引用放行,头像维持上传者排他授权。
  • 契约与文档:
    • openapi.ts:补充 POST /api/write/spaces 端点与相关 Schema,更新读回接口授权描述。
    • api-contract.md:同步建空间及文件读回引用授权契约条款。
    • agent-guide.md:新增「空间导出/导入组装协议」章节,明确流水线端点序列与重映射机制。
    • agent-guide-content.ts:由 scripts/build-info.mjs 自动更新内嵌常量。
  • 测试覆盖:
    • write-api.test.ts:新增写接口建空间权限隔离矩阵、slug 冲突递增及校验失败测试。
    • read-api.test.ts:新增正文/画布/Embed 文件引用授权、软删/越权拒绝及上传者兜底测试。

Testing

  • 本地全量测试通过:pnpm test(170 个测试文件、2173 项测试全部通过)。
  • 本地静态检查通过:pnpm typecheck、pnpm lint、pnpm format:check 均 0 错误。
  • 分支 CI 验证通过:GitHub Actions CI(Run #46134707046)全流程通过。

- Add POST /api/write/spaces endpoint with admin role binding and slug collision resolution
- Restrict space creation to unrestricted write tokens, returning 403 for scoped tokens
- Refactor GET /api/read/files/:key to support dual authorization (referenced page read access and uploader fallback)
- Prevent full-table scan on file reference check by scoping search to authorized spaces
- Sync api-contract.md, openapi.ts, and agent-guide.md with export/import assembly protocols
- Add comprehensive test coverage in write-api.test.ts and read-api.test.ts

Checkpoint: BWkt59ifTMvnLPel7fm7S
@todosdev
todosdev Bot merged commit 2bf422d into main Nov 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant