From 4941e7d7d2db025151e25ed04d939fac2177dc71 Mon Sep 17 00:00:00 2001 From: nineven Date: Sun, 15 Mar 2020 12:33:47 +0800 Subject: [PATCH] fix change head_img --- fir_client/src/components/FirHeader.vue | 6 ++- .../src/components/FirUserProfileBase.vue | 2 +- fir_ser/api/utils/app/analyze.py | 13 ++--- fir_ser/api/views/apps.py | 2 +- fir_ser/api/views/login.py | 54 ++++++++++--------- 5 files changed, 37 insertions(+), 40 deletions(-) diff --git a/fir_client/src/components/FirHeader.vue b/fir_client/src/components/FirHeader.vue index ae1b2fe..3a792a1 100644 --- a/fir_client/src/components/FirHeader.vue +++ b/fir_client/src/components/FirHeader.vue @@ -14,8 +14,10 @@ - - + +
+
+ {{$store.state.userinfo.first_name }} diff --git a/fir_client/src/components/FirUserProfileBase.vue b/fir_client/src/components/FirUserProfileBase.vue index 511722d..991d6c9 100644 --- a/fir_client/src/components/FirUserProfileBase.vue +++ b/fir_client/src/components/FirUserProfileBase.vue @@ -93,7 +93,7 @@ message: '应用图标上传成功', type: 'success' }); - // this.updateUserInfo({"methods":false}); + this.updateUserInfo({"methods":false}); }, beforeAvatarUpload(file) { diff --git a/fir_ser/api/utils/app/analyze.py b/fir_ser/api/utils/app/analyze.py index 6cf97f8..fb1617d 100644 --- a/fir_ser/api/utils/app/analyze.py +++ b/fir_ser/api/utils/app/analyze.py @@ -128,22 +128,15 @@ def delete_apps_storage(app_file_name,release_type): print(e) -def delete_apps_icon_storage(app_file_name): - icon_path = os.path.join(MEDIA_ROOT,"icons") +def delete_apps_icon_storage(app_file_name,type='icons'): + icon_path = os.path.join(MEDIA_ROOT,type) - remove_lists=[ - os.path.join(icon_path, "%s.png" % (app_file_name)) - ] try: - for delfiles in remove_lists: - os.remove(delfiles) + os.remove(os.path.join(icon_path, app_file_name)) except Exception as e: print(e) - - - def get_release_type(app_file_name,appinfo): extension = app_file_name.split(".")[1] if extension == "ipa": diff --git a/fir_ser/api/views/apps.py b/fir_ser/api/views/apps.py index e872678..785edcb 100644 --- a/fir_ser/api/views/apps.py +++ b/fir_ser/api/views/apps.py @@ -209,7 +209,7 @@ class AppinfoView(APIView): return Response(res.dict) release_obj.icon_url = release_obj.icon_url.replace(old_file_name.split(".")[0],random_file_name) release_obj.save() - delete_apps_icon_storage(old_file_name.split(".")[0]) + delete_apps_icon_storage(old_file_name,'icons') else: res.code = 1003 diff --git a/fir_ser/api/views/login.py b/fir_ser/api/views/login.py index c5cf5ce..2052ddf 100644 --- a/fir_ser/api/views/login.py +++ b/fir_ser/api/views/login.py @@ -13,7 +13,7 @@ import binascii import os,datetime from api.utils.app.TokenManager import DownloadToken,generateNumericTokenOfLength from api.utils.auth import ExpiringTokenAuthentication - +from api.utils.app.analyze import delete_apps_icon_storage from api.utils.response import BaseResponse from api.utils.captcha_verify import verify from django.middleware import csrf @@ -140,31 +140,33 @@ class UserInfoView(APIView): res.msg = "错误的类型" return Response(res.dict) - img_file_name = request.user.head_img - if img_file_name == "" or img_file_name == '/files/imgs/head_img.jpeg': - random_file_name = make_from_user_uuid(request.user) - head_img = "/".join([settings.MEDIA_URL.strip("/"), "imgs", random_file_name + "." + app_type]) - try: - request.user.head_img = head_img - request.user.save() - except Exception as e: - res.code = 1003 - res.msg = "头像保存失败" - return Response(res.dict) - else: - random_file_name = os.path.basename(img_file_name) - local_file = os.path.join(settings.MEDIA_ROOT,"imgs",random_file_name) - # 读取传入的文件 - try: - destination = open(local_file, 'wb+') - for chunk in file_obj.chunks(): - # 写入本地文件 - destination.write(chunk) - destination.close() - except Exception as e: - res.code = 1003 - res.msg = "数据写入失败" - return Response(res.dict) + # img_file_name = request.user.head_img + # if img_file_name == "" or img_file_name == '/files/imgs/head_img.jpeg': + old_head_img = request.user.head_img + random_file_name = make_from_user_uuid(request.user) + head_img = "/".join([settings.MEDIA_URL.strip("/"), "imgs", random_file_name + "." + app_type]) + local_file = os.path.join(settings.MEDIA_ROOT,"imgs",random_file_name + "." + app_type) + # 读取传入的文件 + try: + destination = open(local_file, 'wb+') + for chunk in file_obj.chunks(): + # 写入本地文件 + destination.write(chunk) + destination.close() + except Exception as e: + res.code = 1003 + res.msg = "数据写入失败" + return Response(res.dict) + try: + request.user.head_img = head_img + request.user.save() + if old_head_img != "" or old_head_img != '/files/imgs/head_img.jpeg': + delete_apps_icon_storage(os.path.basename(old_head_img),'imgs') + + except Exception as e: + res.code = 1003 + res.msg = "头像保存失败" + return Response(res.dict) return Response(res.dict)