feat(pages): 个人主页未自定义时返回平台默认名片 — 人才档案+已上架服务+头像直链解析
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
- GET /pages/{user_id} 公开渲染数据:页面内容 + 身份条(昵称/头像/信用/徽章)
|
||||
+ 能力接入说明(capabilities 非空 → connected 接入说明;空 → unverified 提醒访客核实)。
|
||||
未发布页仅本人可见(返回 published=false),他人访问返回 404。
|
||||
未设置个人主页或他人访问未上架页 → 返回 page=null + default(人才档案 + 已上架服务)。
|
||||
- GET /pages/me 我的个人主页(含发布状态)
|
||||
- PUT /pages/me 保存个人主页(html 源码 或 embed 第三方网页 + 能力声明)
|
||||
- POST /pages/me/publish 上架/下架
|
||||
@@ -83,9 +83,10 @@ async def _compute_badges(db: Database, user_id: str) -> list[dict]:
|
||||
|
||||
|
||||
def _public_profile(user: dict, badges: list[dict], credit: int | None) -> dict:
|
||||
from ...infrastructure.oss import resolve_url
|
||||
return {
|
||||
"nickname": user.get("nickname") or user.get("username") or "OPC 用户",
|
||||
"avatar": user.get("avatar") or "",
|
||||
"avatar": resolve_url(user.get("avatar") or ""),
|
||||
"creditScore": credit,
|
||||
"badges": badges,
|
||||
}
|
||||
@@ -120,38 +121,57 @@ async def publish_my_page(body: dict = Body(default={}), db: Database = Depends(
|
||||
|
||||
|
||||
# ── 公开渲染数据(人才市场等入口跳转查看)───────────────────────────────
|
||||
@router.get("/{user_id}", summary="获取用户个人主页(公开渲染数据)")
|
||||
@router.get("/{user_id}", summary="获取用户个人主页(公开渲染数据;未设置时返回默认名片数据)")
|
||||
async def get_user_page(user_id: str, db: Database = Depends(get_db),
|
||||
viewer: dict = Depends(get_current_user)):
|
||||
page = await db.user_pages.get(user_id)
|
||||
if page is None:
|
||||
raise HTTPException(status_code=404, detail="该用户尚未创建个人主页")
|
||||
is_self = (viewer.get("id") or "") == user_id
|
||||
if not page.get("published") and not is_self:
|
||||
raise HTTPException(status_code=404, detail="该用户个人主页未上架")
|
||||
|
||||
user = (await db.users.get_by_id(user_id)) or {}
|
||||
if not user:
|
||||
raise HTTPException(status_code=404, detail="用户不存在")
|
||||
is_self = (viewer.get("id") or "") == user_id
|
||||
badges = await _compute_badges(db, user_id)
|
||||
opc_profile = await db.opc_profiles.get(user_id)
|
||||
credit = (opc_profile or {}).get("credit_score")
|
||||
capabilities = page.get("capabilities") or []
|
||||
|
||||
# 已上架(或本人自己的页)→ 渲染用户自写页面
|
||||
if page and (page.get("published") or is_self):
|
||||
capabilities = page.get("capabilities") or []
|
||||
notice = {
|
||||
"type": "connected" if capabilities else "unverified",
|
||||
"capabilities": capabilities,
|
||||
"text": ("本页面已接入平台数据能力,所展示数据为平台实时数据" if capabilities
|
||||
else "本页面内容由用户自行编写,平台未对其中数据与信息进行核验,请注意核实"),
|
||||
}
|
||||
return {
|
||||
"page": {
|
||||
"pageType": page.get("pageType"),
|
||||
"htmlContent": page.get("htmlContent") if page.get("pageType") == "html" else "",
|
||||
"embedUrl": page.get("embedUrl") if page.get("pageType") == "embed" else "",
|
||||
"capabilities": capabilities,
|
||||
"published": page.get("published"),
|
||||
},
|
||||
"profile": _public_profile(user, badges, credit),
|
||||
"notice": notice,
|
||||
"ownerIsSelf": is_self,
|
||||
}
|
||||
|
||||
# 未设置个人主页 / 他人访问未上架页 → 渲染平台默认名片(基础资料 + 已上架服务)
|
||||
talent = await db.hall_talents.get(user_id)
|
||||
services = await db.hall_services.list(status="published", opc_id=user_id)
|
||||
notice = {
|
||||
"type": "connected" if capabilities else "unverified",
|
||||
"capabilities": capabilities,
|
||||
"text": ("本页面已接入平台数据能力,所展示数据为平台实时数据" if capabilities
|
||||
else "本页面内容由用户自行编写,平台未对其中数据与信息进行核验,请注意核实"),
|
||||
"type": "unverified",
|
||||
"capabilities": [],
|
||||
"text": "该用户尚未自定义个人主页,以下内容为平台公开信息,请注意核实",
|
||||
}
|
||||
return {
|
||||
"page": {
|
||||
"pageType": page.get("pageType"),
|
||||
"htmlContent": page.get("htmlContent") if page.get("pageType") == "html" else "",
|
||||
"embedUrl": page.get("embedUrl") if page.get("pageType") == "embed" else "",
|
||||
"capabilities": capabilities,
|
||||
"published": page.get("published"),
|
||||
},
|
||||
"page": None,
|
||||
"profile": _public_profile(user, badges, credit),
|
||||
"notice": notice,
|
||||
"ownerIsSelf": is_self,
|
||||
"default": {
|
||||
"talent": talent,
|
||||
"services": services,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user