|
@@ -738,12 +738,13 @@ class DevicePushService:
|
|
|
return result.full_path if result else ''
|
|
|
|
|
|
@staticmethod
|
|
|
- def create_oci_req_url(storage_location, bucket, obj_name):
|
|
|
+ def create_oci_req_url(storage_location, bucket, obj_name, oci=None):
|
|
|
"""
|
|
|
创建oci预认证请求url
|
|
|
"""
|
|
|
- region = 'eur' if storage_location == 4 else 'us'
|
|
|
- oci = OCIObjectStorage(region)
|
|
|
+ if not oci:
|
|
|
+ region = 'eur' if storage_location == 4 else 'us'
|
|
|
+ oci = OCIObjectStorage(region)
|
|
|
time_expires = datetime.datetime.utcnow() + datetime.timedelta(minutes=60)
|
|
|
result = oci.create_ereauthenticated_request(bucket, 'ociPush', obj_name, time_expires)
|
|
|
if not result:
|
|
@@ -770,7 +771,8 @@ class DevicePushService:
|
|
|
# 区域是国外 并且存储位置OCI
|
|
|
if kwargs['region'] == 1 and kwargs['storage_location'] in [3, 4]:
|
|
|
# OCI
|
|
|
- img_url = DevicePushService.create_oci_req_url(kwargs['storage_location'], params['Bucket'], key_name)
|
|
|
+ img_url = DevicePushService.create_oci_req_url(kwargs['storage_location'], params['Bucket'],
|
|
|
+ key_name)
|
|
|
res_data['img_push'] = img_url
|
|
|
res_data['msg'] = 'success 1'
|
|
|
else:
|
|
@@ -784,13 +786,17 @@ class DevicePushService:
|
|
|
params = {'Bucket': 'push'}
|
|
|
else: # 1:国外
|
|
|
params = {'Bucket': 'foreignpush'}
|
|
|
+ oci_client = None
|
|
|
+ if kwargs['storage_location'] in [3, 4]: # 三张图的时候提前获取实例化OCI
|
|
|
+ region = 'eur' if kwargs['storage_location'] == 4 else 'us'
|
|
|
+ oci_client = OCIObjectStorage(region)
|
|
|
for i in range(kwargs['is_st']):
|
|
|
key_name = '{}/{}/{}_{}.jpeg'.format(kwargs['uid'], kwargs['channel'], kwargs['n_time'], i)
|
|
|
params['Key'] = key_name
|
|
|
- if kwargs['region'] == 1 and kwargs['storage_location'] in [3, 4]:
|
|
|
+ if kwargs['region'] == 1:
|
|
|
# OCI
|
|
|
img_url = DevicePushService.create_oci_req_url(kwargs['storage_location'],
|
|
|
- params['Bucket'], key_name)
|
|
|
+ params['Bucket'], key_name, oci_client)
|
|
|
img_url_list.append(img_url)
|
|
|
else:
|
|
|
# AWS
|