增加 存储切换 自动迁移数据功能

pull/5/head
nineven 4 years ago
parent 641b7643de
commit 51020ed73e
  1. 6
      fir_client/src/components/FirUserProfileStorage.vue
  2. 4
      fir_ser/api/utils/utils.py
  3. 15
      fir_ser/api/views/storage.py

@ -90,8 +90,10 @@
</el-option>
</el-option-group>
</el-select>
<el-button style="margin-left: 10px" round type="info" icon="el-icon-thumb"
@click="change_storage_info">保存
<el-button v-if="use_storage_id!==org_storage_id" style="margin-left: 10px" round type="info"
icon="el-icon-thumb"
@click="change_storage_info">
迁移数据并保存
</el-button>
<!-- <el-button-group style="margin-left: 10px">-->

@ -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

@ -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))

Loading…
Cancel
Save