fix change head_img

storage_local
nineven 5 years ago
parent 9315ec29f6
commit 4941e7d7d2
  1. 6
      fir_client/src/components/FirHeader.vue
  2. 2
      fir_client/src/components/FirUserProfileBase.vue
  3. 13
      fir_ser/api/utils/app/analyze.py
  4. 2
      fir_ser/api/views/apps.py
  5. 28
      fir_ser/api/views/login.py

@ -14,8 +14,10 @@
</el-breadcrumb> </el-breadcrumb>
</el-col> </el-col>
<el-col :span="4" :push="5"> <el-col :span="2" :push="4">
<div class="block"><el-avatar :size="66" :src="$store.state.userinfo.head_img"></el-avatar></div>
</el-col>
<el-col :span="4" :push="4">
<el-dropdown style="padding-top: 12px;" @command="handleCommand"> <el-dropdown style="padding-top: 12px;" @command="handleCommand">
<el-button type="success" plain round> <el-button type="success" plain round>
{{$store.state.userinfo.first_name }}<i class="el-icon-arrow-down el-icon--right"></i> {{$store.state.userinfo.first_name }}<i class="el-icon-arrow-down el-icon--right"></i>

@ -93,7 +93,7 @@
message: '应用图标上传成功', message: '应用图标上传成功',
type: 'success' type: 'success'
}); });
// this.updateUserInfo({"methods":false}); this.updateUserInfo({"methods":false});
}, },
beforeAvatarUpload(file) { beforeAvatarUpload(file) {

@ -128,22 +128,15 @@ def delete_apps_storage(app_file_name,release_type):
print(e) print(e)
def delete_apps_icon_storage(app_file_name): def delete_apps_icon_storage(app_file_name,type='icons'):
icon_path = os.path.join(MEDIA_ROOT,"icons") icon_path = os.path.join(MEDIA_ROOT,type)
remove_lists=[
os.path.join(icon_path, "%s.png" % (app_file_name))
]
try: try:
for delfiles in remove_lists: os.remove(os.path.join(icon_path, app_file_name))
os.remove(delfiles)
except Exception as e: except Exception as e:
print(e) print(e)
def get_release_type(app_file_name,appinfo): def get_release_type(app_file_name,appinfo):
extension = app_file_name.split(".")[1] extension = app_file_name.split(".")[1]
if extension == "ipa": if extension == "ipa":

@ -209,7 +209,7 @@ class AppinfoView(APIView):
return Response(res.dict) return Response(res.dict)
release_obj.icon_url = release_obj.icon_url.replace(old_file_name.split(".")[0],random_file_name) release_obj.icon_url = release_obj.icon_url.replace(old_file_name.split(".")[0],random_file_name)
release_obj.save() release_obj.save()
delete_apps_icon_storage(old_file_name.split(".")[0]) delete_apps_icon_storage(old_file_name,'icons')
else: else:
res.code = 1003 res.code = 1003

@ -13,7 +13,7 @@ import binascii
import os,datetime import os,datetime
from api.utils.app.TokenManager import DownloadToken,generateNumericTokenOfLength from api.utils.app.TokenManager import DownloadToken,generateNumericTokenOfLength
from api.utils.auth import ExpiringTokenAuthentication 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.response import BaseResponse
from api.utils.captcha_verify import verify from api.utils.captcha_verify import verify
from django.middleware import csrf from django.middleware import csrf
@ -140,20 +140,12 @@ class UserInfoView(APIView):
res.msg = "错误的类型" res.msg = "错误的类型"
return Response(res.dict) return Response(res.dict)
img_file_name = request.user.head_img # img_file_name = request.user.head_img
if img_file_name == "" or img_file_name == '/files/imgs/head_img.jpeg': # 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) random_file_name = make_from_user_uuid(request.user)
head_img = "/".join([settings.MEDIA_URL.strip("/"), "imgs", random_file_name + "." + app_type]) head_img = "/".join([settings.MEDIA_URL.strip("/"), "imgs", random_file_name + "." + app_type])
try: local_file = os.path.join(settings.MEDIA_ROOT,"imgs",random_file_name + "." + app_type)
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: try:
destination = open(local_file, 'wb+') destination = open(local_file, 'wb+')
@ -165,6 +157,16 @@ class UserInfoView(APIView):
res.code = 1003 res.code = 1003
res.msg = "数据写入失败" res.msg = "数据写入失败"
return Response(res.dict) 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) return Response(res.dict)

Loading…
Cancel
Save