feat(api): idempotent upload session init with presigned credential

POST /v1/uploads (Task 18, A03): @@unique(userId, clientTaskId) idempotency
anchor — same params return the original session (201, no duplicate photo);
param drift (album/bytes/contentType/extension) -> 409 UPLOAD_SESSION_CONFLICT.
photos.objectKey is set to the FINAL originals key at init while the session
holds the staging key; IDs come from an app-side cuid-like generator so both
self-referencing keys are written in one transaction. Credential is a real
MinIO presigned PUT (SIGNED_URL_TTL_SECONDS, lazily read). Permission order:
album invisible 404 -> member 403 -> uploadEnabled 409 -> size/ext 400 ->
category ownership 400. No audit on init (audit anchors on complete).

Pre-step for Task 19: QUEUE_PHOTO_PROCESS contract constant + lazy-safe
BullMQ queue producer (Redis down at boot must not crash the app; enqueue
failure only logs — sweep compensates). e2e reset now also wipes the MinIO
photo-live/dev prefix; jest maps @photo/storage to TS source.

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-17 22:42:13 +08:00
parent e04e1f3bdf
commit a2a3ccd340
15 changed files with 1252 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
// packages/contracts/src/constants.ts
// 跨服务共享的运行时常量(Task 19 起)。队列名等标识符放契约包:api(生产者,
// complete 后入队)与 worker(Task 20/21 消费者)经同一常量引用,杜绝两处字符串漂移。
/** 照片处理 BullMQ 队列名(api enqueue → worker 消费;补偿扫描 Task 21)。 */
export const QUEUE_PHOTO_PROCESS = 'photo-process';
+1
View File
@@ -2,6 +2,7 @@
// 契约统一出口:错误码 + OpenAPI 生成类型(src/generated/openapi.d.ts 提交入库,
// 消费方不跑 gen;本包改动后执行 pnpm gen 并提交生成文件 diff)。
// NodeNext + ESM:相对导入必须带 .js 扩展名;生成文件仅含类型,用 export type * 在运行时擦除。
export * from './constants.js';
export * from './errors.js';
export * from './events.js';
export type * from './generated/openapi.js';