账号接口 /api/account
用户中心相关接口。全部需要登录令牌。
GET /api/account
返回用户概览与统计。
json
{
"ok": true,
"user": { "id": "1", "email": "you@example.com", "displayName": "You", "avatarUrl": "/uploads/avatars/1-abc.png", "credits": 992, "emailVerified": true, "createdAt": "..." },
"stats": { "activeSessions": 2, "signInCount": 14 }
}PUT /api/account/profile
修改昵称。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
displayName | string | 否 | 最长 60 字;传空串即清空昵称 |
超过长度限制返回 400 name_too_long。
POST /api/account/avatar
上传头像。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
image | string | 是 | base64 data URI,支持 PNG / JPG / WebP,解码后不超过 400 KB |
控制台前端会先用 canvas 把图片居中裁成正方形并压到 256×256 再上传,服务端只做校验与落盘。上传成功后旧头像会被删除。
json
{ "ok": true, "user": { "...": "...", "avatarUrl": "/uploads/avatars/1-abc.png" } }格式不支持或体积超限返回 400 invalid_image。
DELETE /api/account/avatar
删除头像,界面回到昵称首字母占位。
POST /api/account/password
修改密码。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
currentPassword | string | 是 | 当前密码 |
newPassword | string | 是 | 8–72 位,含字母与数字 |
行为:
- 当前密码错误返回
400 wrong_current_password。 - 新密码与当前密码相同返回
400 same_password。 - 修改成功后,除当前设备外的所有会话立即失效。
GET /api/account/sessions
登录设备列表。
json
{
"ok": true,
"sessions": [
{ "id": "12", "current": true, "userAgent": "Mozilla/5.0 ...", "ip": "1.2.3.4", "createdAt": "...", "expiresAt": "..." }
]
}DELETE /api/account/sessions/:id
退出指定设备。
- 传入当前设备自己的 ID 会返回
400 current_session(应改用退出登录)。 - 不属于当前用户的 ID 返回
404 not_found。
DELETE /api/account/sessions
退出除当前设备外的全部设备。
json
{ "ok": true, "revoked": 3 }