diff --git a/fir_ser/api/base_views.py b/fir_ser/api/base_views.py index f9ecd91..b497c2f 100644 --- a/fir_ser/api/base_views.py +++ b/fir_ser/api/base_views.py @@ -9,7 +9,7 @@ from api.utils.response import BaseResponse from api.utils.app.supersignutils import IosUtils from api.utils.storage.storage import Storage from api.utils.storage.caches import del_cache_response_by_short, del_cache_by_delete_app, \ - del_cache_storage + del_cache_storage, MigrateStorageState from api.models import AppReleaseInfo, APPToDeveloper, UserInfo, AppScreenShot, AppStorage import logging from api.utils.utils import delete_local_files, delete_app_screenshots_files, change_storage_and_change_head_img, \ @@ -127,5 +127,5 @@ def storage_change(use_storage_id, user_obj, force): else: return False del_cache_storage(user_obj) - + MigrateStorageState.del_state(user_obj.uid) return True diff --git a/fir_ser/api/utils/storage/caches.py b/fir_ser/api/utils/storage/caches.py index 0034fef..b103dbe 100644 --- a/fir_ser/api/utils/storage/caches.py +++ b/fir_ser/api/utils/storage/caches.py @@ -479,3 +479,25 @@ def get_wx_ticket_login_info_cache(ticket): if wx_ticket_info: cache.delete(wx_t_key) return wx_ticket_info + +class CacheBaseState(object): + prefix='' + def __init__(self, prefix): + CacheBaseState.prefix = prefix + + @classmethod + def get_state(cls, key): + return cache.get(f"{cls.prefix}_{key}") + + @classmethod + def set_state(cls, key,value= time.time(),timeout=3600*24): + cls.del_state(f"{cls.prefix}_{key}") + cache.set(f"{cls.prefix}_{key}",value,timeout) + + @classmethod + def del_state(cls,key): + cache.delete(f"{cls.prefix}_{key}") + +class MigrateStorageState(CacheBaseState): + def __init__(self): + super().__init__('migrate_storage') diff --git a/fir_ser/api/utils/storage/storage.py b/fir_ser/api/utils/storage/storage.py index 9b79190..587d457 100644 --- a/fir_ser/api/utils/storage/storage.py +++ b/fir_ser/api/utils/storage/storage.py @@ -134,6 +134,16 @@ class Storage(object): if self.storage: return self.storage.storage_type + def get_storage_uuid(self): + if self.storage: + if self.storage.storage_type == 1: + return self.storage.access_key + elif self.storage.storage_type == 2: + return self.storage.access_key_id + else: + return self.storage.domain_name + return id(self) + def get_local_storage(clean_cache=False): storage_lists = THIRD_PART_CONFIG.get('storage') diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index 194fde9..154b917 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -195,7 +195,7 @@ def check_storage_is_new_storage(user_obj, new_storage_obj): new_storage_obj = Storage(user_obj, None, True) else: new_storage_obj = Storage(user_obj, new_storage_obj) - if old_storage_obj.get_storage_type() == new_storage_obj.get_storage_type(): + if old_storage_obj.get_storage_uuid() == new_storage_obj.get_storage_uuid(): return False return True @@ -208,7 +208,7 @@ def migrating_storage_file_data(user_obj, filename, new_storage_obj, clean_old_d else: new_storage_obj = Storage(user_obj, new_storage_obj) - if old_storage_obj.get_storage_type() == new_storage_obj.get_storage_type(): + if old_storage_obj.get_storage_uuid() == new_storage_obj.get_storage_uuid(): # 同一个存储,无需迁移数据 return True diff --git a/fir_ser/api/views/storage.py b/fir_ser/api/views/storage.py index 5503b89..46b14c8 100644 --- a/fir_ser/api/views/storage.py +++ b/fir_ser/api/views/storage.py @@ -11,6 +11,7 @@ from api.utils.response import BaseResponse from api.utils.auth import ExpiringTokenAuthentication, StoragePermission from rest_framework.response import Response from api.models import AppStorage, UserInfo +from api.utils.storage.caches import MigrateStorageState from api.utils.utils import upload_oss_default_head_img, get_choices_dict from api.utils.serializer import StorageSerializer import logging @@ -93,6 +94,11 @@ class StorageView(APIView): use_storage_id = data.get("use_storage_id", None) force = data.get("force", None) if use_storage_id: + if MigrateStorageState.get_state(request.user.uid): + res.code = 1007 + res.msg = "数据迁移中,请耐心等待" + return Response(res.dict) + MigrateStorageState.set_state(request.user.uid) if not storage_change(use_storage_id, request.user, force): res.code = 1006 res.msg = '修改失败'