Преглед изворни кода

后台查询推送数据兼容华为云

locky пре 11 месеци
родитељ
комит
dd7995c148
1 измењених фајлова са 14 додато и 1 уклоњено
  1. 14 1
      AdminController/MessageMangementController.py

+ 14 - 1
AdminController/MessageMangementController.py

@@ -7,8 +7,10 @@ from botocore import client
 from django.core.paginator import Paginator
 from django.db.models import Q
 from django.views.generic.base import View
+from obs import ObsClient
 
-from Ansjer.config import CONFIG_EUR, CONFIG_US
+from Ansjer.config import CONFIG_EUR, CONFIG_US, HUAWEICLOUD_PUSH_BUKET, HUAWEICLOUD_AK, HUAWEICLOUD_SK, \
+    HUAWEICLOUD_OBS_SERVER
 from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, \
     SERVER_TYPE
 from Controller.DetectControllerV2 import DetectControllerViewV2
@@ -133,6 +135,9 @@ class MassageView(View):
             # 连接存储桶
             auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
             oss_img_bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
+            # 华为云
+            obs_client = ObsClient(
+                access_key_id=HUAWEICLOUD_AK, secret_access_key=HUAWEICLOUD_SK, server=HUAWEICLOUD_OBS_SERVER)
             aws_s3 = boto3.client(
                 's3',
                 aws_access_key_id=AWS_ACCESS_KEY_ID[1],
@@ -171,6 +176,10 @@ class MassageView(View):
                     thumbspng = '{}/{}/{}.jpeg'.format(uid, channel, event_time)
                     if storage_location == 1:  # 阿里云oss
                         img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
+                    elif storage_location == 5:  # 华为云
+                        create_res = obs_client.createSignedUrl(
+                            method='GET', bucketName=HUAWEICLOUD_PUSH_BUKET, objectKey=thumbspng, expires=300)
+                        img_url = create_res.signedUrl
                     elif storage_location in [3, 4]:
                         prefix_name = f'{uid}/'
                         oci = oci_eur if storage_location == 4 else oci_us
@@ -233,6 +242,10 @@ class MassageView(View):
                         thumbspng = '{}/{}/{}_{}.jpeg'.format(uid, channel, event_time, i)
                         if storage_location == 1:  # 阿里云oss
                             img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
+                        elif storage_location == 5:  # 华为云
+                            create_res = obs_client.createSignedUrl(
+                                method='GET', bucketName=HUAWEICLOUD_PUSH_BUKET, objectKey=thumbspng, expires=300)
+                            img_url = create_res.signedUrl
                         elif storage_location in [3, 4]:  # 国外OCI云
                             prefix_name = f'{uid}/'
                             oci = oci_eur if storage_location == 4 else oci_us