|
@@ -133,7 +133,7 @@ class IcloudServiceView(View):
|
|
|
time_stamp = int(time_stamp) * 1000 # 转换单位为毫秒
|
|
|
icloud_record_qs = IcloudStorageRecord.objects.filter(user_id=user_id, uid=uid, channel=channel,
|
|
|
time_stamp=time_stamp,
|
|
|
- size=ts_size, store_type=1)
|
|
|
+ size=ts_size, file_type=1)
|
|
|
if not icloud_record_qs.exists(): # 转移云盘,并记录上传记录,更新使用容量
|
|
|
for source_key in ts_list:
|
|
|
ts_name = source_key.split('/')[-1]
|
|
@@ -147,7 +147,7 @@ class IcloudServiceView(View):
|
|
|
IcloudStorageRecord.objects.create(user_id=user_id, uid=uid, channel=channel, time_stamp=time_stamp,
|
|
|
nickname=nickname,
|
|
|
sec=sec, bucket_id=target_bucket_id, fg=fg, size=ts_size,
|
|
|
- store_type=1)
|
|
|
+ file_type=1)
|
|
|
use_details_qs.update(use_size=temp_size)
|
|
|
return response.json(0)
|
|
|
else:
|
|
@@ -166,21 +166,25 @@ class IcloudServiceView(View):
|
|
|
@param response: 响应对象
|
|
|
@return: response
|
|
|
"""
|
|
|
- logger.info('开始云存转移到云盘')
|
|
|
+ logger.info('开始本地转移到云盘')
|
|
|
uid = request_dict.get('uid', None)
|
|
|
channel = request_dict.get('channel', None)
|
|
|
- start_time = request_dict.get('start_time', None)
|
|
|
- if not all([uid, channel, start_time]):
|
|
|
- return response.json(444, {'error param': 'uid,channel,start_time'})
|
|
|
+ time_stamp = request_dict.get('time_stamp', None)
|
|
|
+ size = request_dict.get('size', None)
|
|
|
+ file_type = request_dict.get('file_type', None)
|
|
|
+ sec = request_dict.get('sec', 0)
|
|
|
+ if not all([uid, channel, time_stamp, size]):
|
|
|
+ return response.json(444, {'error param': 'uid,channel,time_stamp,size'})
|
|
|
device_qs = Device_Info.objects.filter(UID=uid, userID=user_id).values('NickName')
|
|
|
if not device_qs.exists():
|
|
|
return response.json(173)
|
|
|
# 查询是否开通云盘
|
|
|
- use_details_qs = IcloudUseDetails.objects.filter(user_id=user_id).values('id', 'bucket_id', 'use_size')
|
|
|
+ use_details_qs = IcloudUseDetails.objects.filter(user_id=user_id).values('id', 'use_size', 'bucket_id')
|
|
|
if not use_details_qs.exists():
|
|
|
return response.json(173)
|
|
|
+ size = float(size) # 单位是MB
|
|
|
use_details_id = use_details_qs[0]['id']
|
|
|
- target_bucket_id = use_details_qs[0]['bucket_id']
|
|
|
+ bucket_id = use_details_qs[0]['bucket_id']
|
|
|
use_size = float(use_details_qs[0]['use_size'])
|
|
|
now_time = int(time.time())
|
|
|
nickname = device_qs[0]['NickName']
|
|
@@ -192,67 +196,18 @@ class IcloudServiceView(View):
|
|
|
if use_size > all_size:
|
|
|
logger.info('{}用户套餐总容量为:{},已使用容量为:{}'.format(uid, all_size, use_size))
|
|
|
return response.json(910)
|
|
|
- split_vod_hls_obj = SplitVodHlsObject()
|
|
|
- vod_hls = split_vod_hls_obj.get_vod_hls_data(uid=uid, channel=channel, start_time=start_time).values(
|
|
|
- 'bucket_id', 'fg', 'sec')
|
|
|
- if not vod_hls.exists():
|
|
|
- logger.info('{}用户查无此云存:{}'.format(uid, start_time))
|
|
|
- return response.json(173)
|
|
|
- source_bucket_id = vod_hls[0]['bucket_id']
|
|
|
- fg = int(vod_hls[0]['fg'])
|
|
|
- sec = vod_hls[0]['sec']
|
|
|
- target_bucket_qs = VodBucketModel.objects.filter(id=target_bucket_id).values('bucket')
|
|
|
- if not target_bucket_qs.exists():
|
|
|
- return response.json(173)
|
|
|
- target_bucket_name = target_bucket_qs[0]['bucket']
|
|
|
|
|
|
- source_bucket_qs = VodBucketModel.objects.filter(id=source_bucket_id).values('bucket', 'region', 'mold')
|
|
|
- if not source_bucket_qs.exists():
|
|
|
- return response.json(173)
|
|
|
- bucket_region = source_bucket_qs[0]['region']
|
|
|
- source_bucket_name = source_bucket_qs[0]['bucket']
|
|
|
- mold = source_bucket_qs[0]["mold"]
|
|
|
- ts_list = []
|
|
|
- ts_size = 0
|
|
|
try:
|
|
|
- s3_obj = AmazonS3Util(
|
|
|
- AWS_ACCESS_KEY_ID[mold],
|
|
|
- AWS_SECRET_ACCESS_KEY[mold],
|
|
|
- bucket_region
|
|
|
- )
|
|
|
- # 获取s3对象,并计算总字节
|
|
|
- for i in range(15):
|
|
|
- shift = (i + 1) * 4
|
|
|
- duration = (fg >> shift) & 0xf
|
|
|
- if duration > 0:
|
|
|
- ts_file = '{uid}/vod{channel}/{time}/ts{i}.ts'.format(uid=uid, channel=channel, time=start_time,
|
|
|
- i=i)
|
|
|
- ts_list.append(ts_file)
|
|
|
- ts_size += s3_obj.get_object_size(source_bucket_name, ts_file) # 获取存储对象字节,单位B
|
|
|
- ts_size = round(ts_size / 1024 / 1024, 2) # 字节转换为MB单位
|
|
|
- temp_size = ts_size + use_size
|
|
|
- if temp_size > all_size:
|
|
|
- logger.info('{}用户无空间上传,套餐容量为:{},使用容量为:{}'.format(uid, all_size, temp_size))
|
|
|
- return response.json(910)
|
|
|
- start_time = int(start_time) * 1000 # 转换单位为毫秒
|
|
|
+ new_size = round(use_size + size, 2)
|
|
|
icloud_record_qs = IcloudStorageRecord.objects.filter(user_id=user_id, uid=uid, channel=channel,
|
|
|
- time_stamp=start_time,
|
|
|
- size=ts_size, store_type=1)
|
|
|
- if not icloud_record_qs.exists(): # 转移云盘,并记录上传记录,更新使用容量
|
|
|
- for source_key in ts_list:
|
|
|
- ts_name = source_key.split('/')[-1]
|
|
|
- target_key = '{user_id}/ts_file/{uid}/vod{channel}/{time}/{ts_name}'.format(user_id=user_id,
|
|
|
- uid=uid,
|
|
|
- channel=channel,
|
|
|
- time=start_time,
|
|
|
- ts_name=ts_name)
|
|
|
- s3_obj.copy_single_obj(source_bucket_name, source_key, target_bucket_name, target_key)
|
|
|
-
|
|
|
- IcloudStorageRecord.objects.create(user_id=user_id, uid=uid, channel=channel, time_stamp=start_time,
|
|
|
+ time_stamp=time_stamp,
|
|
|
+ size=size, file_type=file_type)
|
|
|
+ if not icloud_record_qs.exists():
|
|
|
+ IcloudStorageRecord.objects.create(user_id=user_id, uid=uid, channel=channel, time_stamp=time_stamp,
|
|
|
nickname=nickname,
|
|
|
- sec=sec, bucket_id=target_bucket_id, fg=fg, size=ts_size,
|
|
|
- store_type=1)
|
|
|
- use_details_qs.update(use_size=temp_size)
|
|
|
+ sec=sec, bucket_id=bucket_id, size=size,
|
|
|
+ file_type=file_type)
|
|
|
+ use_details_qs.update(use_size=new_size)
|
|
|
return response.json(0)
|
|
|
else:
|
|
|
return response.json(174)
|