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