|
@@ -16,10 +16,12 @@ import time
|
|
|
import boto3
|
|
|
import botocore
|
|
|
import requests
|
|
|
+from obs import ObsClient
|
|
|
|
|
|
from AnsjerPush.Config.aiConfig import DEVICE_EVENT_TYPE, ALGORITHM_COMBO_TYPES
|
|
|
from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, MULTI_CHANNEL_TYPE_LIST, SYS_EVENT_TYPE_LIST, AWS_ACCESS_KEY_ID, \
|
|
|
- AWS_SECRET_ACCESS_KEY, EVENT_DICT, EVENT_DICT_CN, CONFIG_TEST
|
|
|
+ AWS_SECRET_ACCESS_KEY, EVENT_DICT, EVENT_DICT_CN, CONFIG_TEST, HUAWEICLOUD_AK, HUAWEICLOUD_SK, \
|
|
|
+ HUAWEICLOUD_OBS_SERVER, HUAWEICLOUD_PUSH_BUKET
|
|
|
from AnsjerPush.config import XMPUSH_CONFIG, OPPOPUSH_CONFIG, XM_PUSH_CHANNEL_ID
|
|
|
from Model.models import UidPushModel, SysMsgModel, DeviceSharePermission, DeviceChannelUserSet, \
|
|
|
DeviceChannelUserPermission, UidSetModel, Device_Info, UserAudioVideoPush
|
|
@@ -713,6 +715,8 @@ class DevicePushService:
|
|
|
try:
|
|
|
if storage_reg in [3, 4]:
|
|
|
image_url = DevicePushService.oci_object_url(storage_reg, bucket, key)
|
|
|
+ elif storage_reg == 5:
|
|
|
+ image_url = DevicePushService.create_obs_signed_url(uid, channel, n_time, 'GET')
|
|
|
else:
|
|
|
image_url = aws_s3_client.generate_presigned_url(
|
|
|
'get_object', Params={'Bucket': bucket, 'Key': key}, ExpiresIn=3600)
|
|
@@ -769,6 +773,7 @@ class DevicePushService:
|
|
|
"""
|
|
|
res_data = {'code': 0, 'msg': 'success'}
|
|
|
is_st = kwargs['is_st']
|
|
|
+ storage_location = kwargs['storage_location']
|
|
|
if is_st == 0 or is_st == 2:
|
|
|
res_data['msg'] = 'success 0 or 2'
|
|
|
elif is_st == 1:
|
|
@@ -779,16 +784,15 @@ class DevicePushService:
|
|
|
else: # 1:国外
|
|
|
params['Bucket'] = 'foreignpush'
|
|
|
# 区域是国外 并且存储位置OCI
|
|
|
- if kwargs['region'] == 1 and kwargs['storage_location'] in [3, 4]:
|
|
|
+ if kwargs['region'] == 1 and 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(storage_location, params['Bucket'], key_name)
|
|
|
res_data['img_push'] = img_url
|
|
|
res_data['msg'] = 'success 1'
|
|
|
else:
|
|
|
- # AWS
|
|
|
- img_url = DevicePushService.generate_s3_url(kwargs['aws_s3_client'], params)
|
|
|
- res_data['img_push'] = img_url
|
|
|
+ # 华为云
|
|
|
+ img_url = DevicePushService.create_obs_signed_url(
|
|
|
+ params['uid'], params['channel'], params['n_time'], 'PUT')
|
|
|
res_data['msg'] = 'success 1'
|
|
|
elif is_st == 3:
|
|
|
img_url_list = []
|
|
@@ -797,21 +801,20 @@ class DevicePushService:
|
|
|
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'
|
|
|
+ if storage_location in [3, 4]: # 三张图的时候提前获取实例化OCI
|
|
|
+ region = 'eur' if 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:
|
|
|
# OCI
|
|
|
- img_url = DevicePushService.create_oci_req_url(kwargs['storage_location'],
|
|
|
- params['Bucket'], key_name, oci_client)
|
|
|
+ img_url = DevicePushService.create_oci_req_url(storage_location, params['Bucket'], key_name, oci_client)
|
|
|
img_url_list.append(img_url)
|
|
|
else:
|
|
|
- # AWS
|
|
|
- img_url = DevicePushService.generate_s3_url(kwargs['aws_s3_client'], params)
|
|
|
- img_url_list.append(img_url)
|
|
|
+ # 华为云
|
|
|
+ img_url = DevicePushService.create_obs_signed_url(
|
|
|
+ params['uid'], params['channel'], params['n_time'], 'PUT')
|
|
|
res_data['img_url_list'] = img_url_list
|
|
|
res_data['msg'] = 'success 3'
|
|
|
return res_data
|
|
@@ -828,6 +831,18 @@ class DevicePushService:
|
|
|
)
|
|
|
return response_url
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def create_obs_signed_url(uid, channel, n_time, method):
|
|
|
+ """
|
|
|
+ 生成对象存储预签名URL
|
|
|
+ """
|
|
|
+ object_key = '{}/{}/{}.jpeg'.format(uid, channel, n_time)
|
|
|
+ obs_client = ObsClient(
|
|
|
+ access_key_id=HUAWEICLOUD_AK, secret_access_key=HUAWEICLOUD_SK, server=HUAWEICLOUD_OBS_SERVER)
|
|
|
+ res = obs_client.createSignedUrl(
|
|
|
+ method=method, bucketName=HUAWEICLOUD_PUSH_BUKET, objectKey=object_key, expires=3600)
|
|
|
+ return res.signedUrl
|
|
|
+
|
|
|
@staticmethod
|
|
|
def check_share_permission(user_id, channel, uid):
|
|
|
"""
|