From 51020ed73e3797c7f49f7006c4a5483a86e5dffb Mon Sep 17 00:00:00 2001 From: nineven Date: Sat, 13 Mar 2021 17:20:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=88=87=E6=8D=A2=20=E8=87=AA=E5=8A=A8=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/FirUserProfileStorage.vue | 6 ++++-- fir_ser/api/utils/utils.py | 4 ++-- fir_ser/api/views/storage.py | 15 ++++++++++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/fir_client/src/components/FirUserProfileStorage.vue b/fir_client/src/components/FirUserProfileStorage.vue index 05bcc54..27be1f0 100644 --- a/fir_client/src/components/FirUserProfileStorage.vue +++ b/fir_client/src/components/FirUserProfileStorage.vue @@ -90,8 +90,10 @@ - 保存 + + 迁移数据并保存 diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index d4a7c4f..ac7d87b 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -314,7 +314,7 @@ def migrating_storage_data(user_obj, new_storage_obj, clean_old_data): for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): filename = get_filename_from_apptype(apptodev_obj.binary_file, app_release_obj.release_type) migrating_storage_file_data(user_obj, filename, new_storage_obj, clean_old_data) - + return True def clean_storage_data(user_obj, storage_obj=None): storage_obj = Storage(user_obj, storage_obj) @@ -323,4 +323,4 @@ def clean_storage_data(user_obj, storage_obj=None): storage_obj.delete_file(app_release_obj.icon_url) for apptodev_obj in APPToDeveloper.objects.filter(app_id=app_release_obj.app_id).all(): storage_obj.delete_file(apptodev_obj.binary_file, app_release_obj.release_type) - + return True diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py index c49fdb1..4612409 100644 --- a/fir_ser/api/views/storage.py +++ b/fir_ser/api/views/storage.py @@ -11,7 +11,7 @@ from rest_framework.response import Response from api.utils.storage.caches import del_cache_storage from api.models import AppStorage, UserInfo from api.utils.utils import upload_oss_default_head_img, check_storage_additionalparameter, \ - change_storage_and_change_head_img + change_storage_and_change_head_img, migrating_storage_data, clean_storage_data from api.utils.serializer import StorageSerializer import logging @@ -91,18 +91,23 @@ class StorageView(APIView): use_storage_id = data.get("use_storage_id", None) if use_storage_id: + if request.user.storage and use_storage_id == request.user.storage.id: + return Response(res.dict) try: if use_storage_id == -1: change_storage_and_change_head_img(request.user, None) - UserInfo.objects.filter(pk=request.user.pk).update(storage=None) - + if migrating_storage_data(request.user, None, False): + clean_storage_data(request.user) + UserInfo.objects.filter(pk=request.user.pk).update(storage=None) else: new_storage_obj = AppStorage.objects.filter(pk=use_storage_id).first() change_storage_and_change_head_img(request.user, new_storage_obj) - UserInfo.objects.filter(pk=request.user.pk).update(storage_id=use_storage_id) + + if migrating_storage_data(request.user, new_storage_obj, False): + clean_storage_data(request.user) + UserInfo.objects.filter(pk=request.user.pk).update(storage_id=use_storage_id) del_cache_storage(request.user) - # change_storage_and_change_head_img(request.user, old_storage_obj, new_storage_obj) except Exception as e: logger.error("update user %s storage failed Exception:%s" % (request.user, e))