From d039cc69e17b98fae1e85be10b8b8973d49d7ab0 Mon Sep 17 00:00:00 2001 From: BryantHe Date: Sat, 19 Aug 2023 12:31:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=8E=A5=E5=8F=A3=E7=9A=84=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/v1/schema/user.py | 3 ++- app/api/v1/user.py | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/api/v1/schema/user.py b/app/api/v1/schema/user.py index fd82297..3b86885 100644 --- a/app/api/v1/schema/user.py +++ b/app/api/v1/schema/user.py @@ -1,5 +1,5 @@ from apiflask import Schema -from apiflask.fields import String, Float +from apiflask.fields import String, Float, URL class UserInfoIn(Schema): @@ -10,4 +10,5 @@ class UserInfoIn(Schema): class UserInfoOut(Schema): nickname = String() avatar_id = String() + avatar_url = URL() height = Float(allow_nan=True) \ No newline at end of file diff --git a/app/api/v1/user.py b/app/api/v1/user.py index c234e93..5dc2210 100644 --- a/app/api/v1/user.py +++ b/app/api/v1/user.py @@ -2,6 +2,7 @@ from apiflask import APIBlueprint from flask import session from app import rpc +from app.api.v1.exception.api import ImageNotFound from app.api.v1.exception.user import UserInfoNotFound, UserInfoError from app.api.v1.schema.user import UserInfoIn, UserInfoOut from app.util.auth import login_required @@ -40,16 +41,23 @@ def get_user_info(): except Exception as e: raise UserInfoNotFound(extra_data={'error_docs': str(e)}) + try: + presign_url = rpc.storage.get_presign_url(user_dict['avatar_id'], + 'bodyrecord', + bucket='bodyrecord') + user_dict['avatar_url'] = presign_url + except Exception as e: + raise ImageNotFound(extra_data={'error_docs': str(e)}) + try: body_info_dict = rpc.body_record.get_body_info(session['user_id']) except Exception as e: raise UserInfoNotFound(extra_data={'error_docs': str(e)}) - if user_dict: - result.update(user_dict) - if body_info_dict: - result['height'] = body_info_dict.get('height', None) - else: - result['height'] = None + result.update(user_dict) + if body_info_dict: + result['height'] = body_info_dict.get('height', None) + else: + result['height'] = None return result