|
|
@ -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,31 +140,33 @@ 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': |
|
|
|
random_file_name = make_from_user_uuid(request.user) |
|
|
|
old_head_img = request.user.head_img |
|
|
|
head_img = "/".join([settings.MEDIA_URL.strip("/"), "imgs", random_file_name + "." + app_type]) |
|
|
|
random_file_name = make_from_user_uuid(request.user) |
|
|
|
try: |
|
|
|
head_img = "/".join([settings.MEDIA_URL.strip("/"), "imgs", random_file_name + "." + app_type]) |
|
|
|
request.user.head_img = head_img |
|
|
|
local_file = os.path.join(settings.MEDIA_ROOT,"imgs",random_file_name + "." + app_type) |
|
|
|
request.user.save() |
|
|
|
# 读取传入的文件 |
|
|
|
except Exception as e: |
|
|
|
try: |
|
|
|
res.code = 1003 |
|
|
|
destination = open(local_file, 'wb+') |
|
|
|
res.msg = "头像保存失败" |
|
|
|
for chunk in file_obj.chunks(): |
|
|
|
return Response(res.dict) |
|
|
|
# 写入本地文件 |
|
|
|
else: |
|
|
|
destination.write(chunk) |
|
|
|
random_file_name = os.path.basename(img_file_name) |
|
|
|
destination.close() |
|
|
|
local_file = os.path.join(settings.MEDIA_ROOT,"imgs",random_file_name) |
|
|
|
except Exception as e: |
|
|
|
# 读取传入的文件 |
|
|
|
res.code = 1003 |
|
|
|
try: |
|
|
|
res.msg = "数据写入失败" |
|
|
|
destination = open(local_file, 'wb+') |
|
|
|
return Response(res.dict) |
|
|
|
for chunk in file_obj.chunks(): |
|
|
|
try: |
|
|
|
# 写入本地文件 |
|
|
|
request.user.head_img = head_img |
|
|
|
destination.write(chunk) |
|
|
|
request.user.save() |
|
|
|
destination.close() |
|
|
|
if old_head_img != "" or old_head_img != '/files/imgs/head_img.jpeg': |
|
|
|
except Exception as e: |
|
|
|
delete_apps_icon_storage(os.path.basename(old_head_img),'imgs') |
|
|
|
res.code = 1003 |
|
|
|
|
|
|
|
res.msg = "数据写入失败" |
|
|
|
except Exception as e: |
|
|
|
return Response(res.dict) |
|
|
|
res.code = 1003 |
|
|
|
|
|
|
|
res.msg = "头像保存失败" |
|
|
|
|
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|
return Response(res.dict) |
|
|
|
return Response(res.dict) |
|
|
|
|
|
|
|
|
|
|
|