fix: sync virtual user profiles to Huihui public pages

This commit is contained in:
stefanfeng
2026-08-17 17:50:11 +08:00
parent 0b3221c4f4
commit 472dce7cae
3 changed files with 219 additions and 24 deletions
+8 -6
View File
@@ -355,13 +355,15 @@ async def upload_avatar(
# 未登录用户本地落盘,避免 base64 超过 avatar_url 字段长度
avatar_url = await _save_local_avatar(file_bytes, file.filename or "", file.content_type)
# 更新数据库
await db.execute(update(_VU).where(_VU.id == user_id).values(avatar_url=avatar_url))
await db.commit()
# 如果已同步到平台,再调用 update_user_profile 更新头像字段
# 已登录用户必须同时写入会会当前资料和“TA 的主页”。
# 任一接口失败都不得返回“头像更新成功”。
if sync_to_platform and user.status == 2 and avatar_url:
await news_service.update_user_profile(db, user, avatar=avatar_url)
ok, err = await news_service.update_user_profile(db, user, avatar=avatar_url)
if not ok:
return ApiResponse(code=502, message=f"头像已上传,但同步到会会失败: {err}")
else:
await db.execute(update(_VU).where(_VU.id == user_id).values(avatar_url=avatar_url))
await db.commit()
return ApiResponse(data={"avatar_url": avatar_url}, message="头像更新成功")
@router.post("/logout-all")