feat(api): password change endpoint and source device id on uploads
P3 Task 3 契约增补批次(单一事实来源 openapi.yaml + cn 实现 + e2e):
- POST /v1/auth/password-change(operationId changePassword,需求 4.1 的
P1 契约缺口补齐):Bearer + {oldPassword 1-128, newPassword 8-128} → 204;
旧密码错误 401 AUTH_INVALID_CREDENTIALS;成功后事务内更新 argon2 哈希、
撤销该用户除当前会话外的全部其他会话(当前会话保留,本人不下线)、写
审计 auth.password_change。
- sourceDeviceId(A19 设备来源语义):UploadInitRequest 可选 8-64 位设备
标识;upload_sessions 落列(VARCHAR(64) utf8mb4_0900_bin,可空,存量
行 NULL 兼容);GET /uploads 条目回显;幂等重放不比对(first-writer,
首次落库值不随重放漂移)。
- e2e:auth 增 4 例(未认证 401 / 新密码过短 400 / 旧密码错误 401 且会话
无副作用 / 成功后他端会话撤销当前保留 + 新旧密码登录裁决 + 审计);
uploads 增 1 例(携带落库回显、换设备重放保留首值、缺省 null、长度
越界 400)。api e2e 179 → 184;contracts gen/redocly/单测、worker、
sync 门全绿。
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -152,6 +152,41 @@ paths:
|
||||
'500':
|
||||
$ref: '#/components/responses/InternalError'
|
||||
|
||||
/auth/password-change:
|
||||
post:
|
||||
operationId: changePassword
|
||||
tags: [auth]
|
||||
summary: 修改密码
|
||||
description: |
|
||||
已认证用户修改自身密码:校验旧密码,成功后更新密码哈希并撤销该用户
|
||||
除当前会话外的全部其他会话(当前会话保持有效,无需重新登录)。
|
||||
P3 Task 3 契约增补(需求 4.1「支持修改密码」,P1 契约缺口补齐)。
|
||||
security:
|
||||
- bearerAuth: []
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/PasswordChangeRequest'
|
||||
responses:
|
||||
'204':
|
||||
description: 修改成功,无响应体;当前会话保留,其他会话已撤销。
|
||||
'400':
|
||||
description: 参数校验失败(VALIDATION_FAILED,经全局校验管道)。
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'401':
|
||||
description: 旧密码错误(AUTH_INVALID_CREDENTIALS)。
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Error'
|
||||
'500':
|
||||
$ref: '#/components/responses/InternalError'
|
||||
|
||||
# ─────────────────────────── albums ───────────────────────────
|
||||
|
||||
/albums:
|
||||
@@ -1674,6 +1709,21 @@ components:
|
||||
format: date-time
|
||||
readOnly: true
|
||||
description: 续期后的过期时间。
|
||||
PasswordChangeRequest:
|
||||
type: object
|
||||
description: 修改密码请求(P3 Task 3 契约增补)。
|
||||
required: [oldPassword, newPassword]
|
||||
properties:
|
||||
oldPassword:
|
||||
type: string
|
||||
minLength: 1
|
||||
maxLength: 128
|
||||
description: 当前密码。
|
||||
newPassword:
|
||||
type: string
|
||||
minLength: 8
|
||||
maxLength: 128
|
||||
description: 新密码(至少 8 位)。
|
||||
|
||||
# ── 相册 ──
|
||||
|
||||
@@ -2138,6 +2188,13 @@ components:
|
||||
type: string
|
||||
enum: [image/jpeg, image/png, image/heic]
|
||||
description: MIME 类型白名单;image/heic 为暂定项,解码能力待 G2 真机验证后确认。
|
||||
sourceDeviceId:
|
||||
type: string
|
||||
minLength: 8
|
||||
maxLength: 64
|
||||
description: |
|
||||
客户端首次生成并持久化的设备标识;服务端历史返回用于区分上传来源
|
||||
(A19)。可选;同一 clientTaskId 幂等重放时保留首次落库的值。
|
||||
|
||||
UploadCredential:
|
||||
type: object
|
||||
@@ -2257,6 +2314,12 @@ components:
|
||||
format: date-time
|
||||
readOnly: true
|
||||
description: 会话创建时间。
|
||||
sourceDeviceId:
|
||||
type: [string, 'null']
|
||||
readOnly: true
|
||||
description: |
|
||||
发起该上传的设备标识(客户端首次生成并持久化;init 时未携带为 null)。
|
||||
P3 Task 3 契约增补(A19 设备来源语义)。
|
||||
photo:
|
||||
$ref: '#/components/schemas/UploadSessionPhoto'
|
||||
|
||||
|
||||
+80
@@ -64,6 +64,28 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/auth/password-change": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* 修改密码
|
||||
* @description 已认证用户修改自身密码:校验旧密码,成功后更新密码哈希并撤销该用户
|
||||
* 除当前会话外的全部其他会话(当前会话保持有效,无需重新登录)。
|
||||
* P3 Task 3 契约增补(需求 4.1「支持修改密码」,P1 契约缺口补齐)。
|
||||
*/
|
||||
post: operations["changePassword"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/albums": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -787,6 +809,13 @@ export interface components {
|
||||
*/
|
||||
readonly expiresAt: string;
|
||||
};
|
||||
/** @description 修改密码请求(P3 Task 3 契约增补)。 */
|
||||
PasswordChangeRequest: {
|
||||
/** @description 当前密码。 */
|
||||
oldPassword: string;
|
||||
/** @description 新密码(至少 8 位)。 */
|
||||
newPassword: string;
|
||||
};
|
||||
/** @description 相册多语言条目(创建/更新与响应共用;未填的可选字段存储为 null)。 */
|
||||
AlbumTranslation: {
|
||||
locale: components["schemas"]["Locale"];
|
||||
@@ -1061,6 +1090,11 @@ export interface components {
|
||||
* @enum {string}
|
||||
*/
|
||||
contentType: "image/jpeg" | "image/png" | "image/heic";
|
||||
/**
|
||||
* @description 客户端首次生成并持久化的设备标识;服务端历史返回用于区分上传来源
|
||||
* (A19)。可选;同一 clientTaskId 幂等重放时保留首次落库的值。
|
||||
*/
|
||||
sourceDeviceId?: string;
|
||||
};
|
||||
/** @description staging 对象的临时直传凭证;仅可写入指定 objectKey,不可访问 originals/variants。 */
|
||||
UploadCredential: {
|
||||
@@ -1128,6 +1162,11 @@ export interface components {
|
||||
* @description 会话创建时间。
|
||||
*/
|
||||
readonly createdAt: string;
|
||||
/**
|
||||
* @description 发起该上传的设备标识(客户端首次生成并持久化;init 时未携带为 null)。
|
||||
* P3 Task 3 契约增补(A19 设备来源语义)。
|
||||
*/
|
||||
readonly sourceDeviceId?: string | null;
|
||||
photo: components["schemas"]["UploadSessionPhoto"];
|
||||
};
|
||||
UploadSessionList: components["schemas"]["CursorPageMeta"] & {
|
||||
@@ -1702,6 +1741,47 @@ export interface operations {
|
||||
500: components["responses"]["InternalError"];
|
||||
};
|
||||
};
|
||||
changePassword: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["PasswordChangeRequest"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description 修改成功,无响应体;当前会话保留,其他会话已撤销。 */
|
||||
204: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content?: never;
|
||||
};
|
||||
/** @description 参数校验失败(VALIDATION_FAILED,经全局校验管道)。 */
|
||||
400: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description 旧密码错误(AUTH_INVALID_CREDENTIALS)。 */
|
||||
401: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
500: components["responses"]["InternalError"];
|
||||
};
|
||||
};
|
||||
listAlbums: {
|
||||
parameters: {
|
||||
query?: {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
-- P3 Task 3:upload_sessions 增 sourceDeviceId(A19 设备来源语义)——客户端
|
||||
-- 首次生成并持久化的设备标识,init 时可选携带、会话历史回显;幂等重放保留
|
||||
-- 首次落库值(first-writer,见 uploads.service paramsMatch 不比对该项)。
|
||||
-- VARCHAR 列显式 utf8mb4_0900_bin(沿用库级约定:--create-only 后手工定校对,
|
||||
-- Prisma 生成 DDL 固定 unicode_ci)。可空新列,存量行(NULL=未上报设备)与
|
||||
-- 既有流程不受影响。
|
||||
ALTER TABLE `upload_sessions` ADD COLUMN `sourceDeviceId` VARCHAR(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_bin NULL;
|
||||
@@ -178,18 +178,19 @@ model photo_variants {
|
||||
@@unique([photoId, variant])
|
||||
}
|
||||
model upload_sessions {
|
||||
id String @id @default(cuid())
|
||||
userId String @db.VarChar(64)
|
||||
albumId String @db.VarChar(64)
|
||||
clientTaskId String @db.VarChar(128)
|
||||
photoId String @unique @db.VarChar(64)
|
||||
objectKey String @unique @db.VarChar(255) // staging 键
|
||||
expectedBytes Int
|
||||
contentType String @db.VarChar(128)
|
||||
multipartId String? @db.VarChar(255)
|
||||
state String @default("pending") // pending|confirmed|cancelled|expired(对齐契约 UploadSessionState;核验失败是请求级错误不改会话态,expired 由 expiresAt 判定或 sweep 置位)
|
||||
expiresAt DateTime @db.DateTime(6)
|
||||
createdAt DateTime @default(now()) @db.DateTime(6)
|
||||
id String @id @default(cuid())
|
||||
userId String @db.VarChar(64)
|
||||
albumId String @db.VarChar(64)
|
||||
clientTaskId String @db.VarChar(128)
|
||||
photoId String @unique @db.VarChar(64)
|
||||
objectKey String @unique @db.VarChar(255) // staging 键
|
||||
expectedBytes Int
|
||||
contentType String @db.VarChar(128)
|
||||
sourceDeviceId String? @db.VarChar(64) // 客户端设备标识(A19 来源语义;幂等重放保留首值)
|
||||
multipartId String? @db.VarChar(255)
|
||||
state String @default("pending") // pending|confirmed|cancelled|expired(对齐契约 UploadSessionState;核验失败是请求级错误不改会话态,expired 由 expiresAt 判定或 sweep 置位)
|
||||
expiresAt DateTime @db.DateTime(6)
|
||||
createdAt DateTime @default(now()) @db.DateTime(6)
|
||||
@@unique([userId, clientTaskId]) // 幂等锚点(A03)
|
||||
}
|
||||
model photo_jobs {
|
||||
|
||||
Reference in New Issue
Block a user