修复存储迁移失败的问题

dependabot/npm_and_yarn/fir_admin/tmpl-1.0.5
youngS 3 years ago
parent 749d72b513
commit 4316398d82
  1. 4
      fir_ser/api/base_views.py
  2. 22
      fir_ser/api/utils/storage/caches.py
  3. 10
      fir_ser/api/utils/storage/storage.py
  4. 4
      fir_ser/api/utils/utils.py
  5. 6
      fir_ser/api/views/storage.py

@ -9,7 +9,7 @@ from api.utils.response import BaseResponse
from api.utils.app.supersignutils import IosUtils from api.utils.app.supersignutils import IosUtils
from api.utils.storage.storage import Storage from api.utils.storage.storage import Storage
from api.utils.storage.caches import del_cache_response_by_short, del_cache_by_delete_app, \ 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 from api.models import AppReleaseInfo, APPToDeveloper, UserInfo, AppScreenShot, AppStorage
import logging import logging
from api.utils.utils import delete_local_files, delete_app_screenshots_files, change_storage_and_change_head_img, \ 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: else:
return False return False
del_cache_storage(user_obj) del_cache_storage(user_obj)
MigrateStorageState.del_state(user_obj.uid)
return True return True

@ -479,3 +479,25 @@ def get_wx_ticket_login_info_cache(ticket):
if wx_ticket_info: if wx_ticket_info:
cache.delete(wx_t_key) cache.delete(wx_t_key)
return wx_ticket_info 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')

@ -134,6 +134,16 @@ class Storage(object):
if self.storage: if self.storage:
return self.storage.storage_type 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): def get_local_storage(clean_cache=False):
storage_lists = THIRD_PART_CONFIG.get('storage') storage_lists = THIRD_PART_CONFIG.get('storage')

@ -195,7 +195,7 @@ def check_storage_is_new_storage(user_obj, new_storage_obj):
new_storage_obj = Storage(user_obj, None, True) new_storage_obj = Storage(user_obj, None, True)
else: else:
new_storage_obj = Storage(user_obj, new_storage_obj) 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 False
return True return True
@ -208,7 +208,7 @@ def migrating_storage_file_data(user_obj, filename, new_storage_obj, clean_old_d
else: else:
new_storage_obj = Storage(user_obj, new_storage_obj) 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 return True

@ -11,6 +11,7 @@ from api.utils.response import BaseResponse
from api.utils.auth import ExpiringTokenAuthentication, StoragePermission from api.utils.auth import ExpiringTokenAuthentication, StoragePermission
from rest_framework.response import Response from rest_framework.response import Response
from api.models import AppStorage, UserInfo 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.utils import upload_oss_default_head_img, get_choices_dict
from api.utils.serializer import StorageSerializer from api.utils.serializer import StorageSerializer
import logging import logging
@ -93,6 +94,11 @@ class StorageView(APIView):
use_storage_id = data.get("use_storage_id", None) use_storage_id = data.get("use_storage_id", None)
force = data.get("force", None) force = data.get("force", None)
if use_storage_id: 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): if not storage_change(use_storage_id, request.user, force):
res.code = 1006 res.code = 1006
res.msg = '修改失败' res.msg = '修改失败'

Loading…
Cancel
Save