浏览代码

优化访问oci

zhangdongming 1 年之前
父节点
当前提交
1555591f11
共有 1 个文件被更改,包括 15 次插入9 次删除
  1. 15 9
      Controller/DetectControllerV2.py

+ 15 - 9
Controller/DetectControllerV2.py

@@ -11,6 +11,7 @@ from django.views.generic.base import View
 
 from Ansjer.config import DETECT_PUSH_DOMAIN, DETECT_PUSH_DOMAINS, DETECT_PUSH_DOMAIN_JIUAN, DETECT_PUSH_DOMAINS_JIUAN, \
     OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, LOGGER, ALGORITHM_COMBO_TYPES
+from Ansjer.config import PUSH_BUCKET
 from Model.models import Device_Info, Equipment_Info, UidSetModel, UidPushModel, CompanyModel, SysMsgModel, \
     AiService, VodBucketModel
 from Object.ETkObject import ETkObject
@@ -22,7 +23,6 @@ from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService
 from Service.VodHlsService import SplitVodHlsObject
-from Ansjer.config import PUSH_BUCKET
 
 
 class DetectControllerViewV2(View):
@@ -371,7 +371,8 @@ class DetectControllerViewV2(View):
                 config=botocore.client.Config(signature_version='s3v4'),
                 region_name='cn-northwest-1'
             )
-
+            oci_eur = OCIObjectStorage('eur')
+            oci_us = OCIObjectStorage('us')
             # ai消息标识所有组合标签
             ai_all_event_type = EquipmentInfoService.get_all_comb_event_type()
             for equipment_info in equipment_info_qs:
@@ -388,7 +389,8 @@ class DetectControllerViewV2(View):
                     if storage_location == 1:  # 阿里云oss
                         img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                     elif storage_location in [3, 4]:
-                        img_url = DetectControllerViewV2.oci_object_url(storage_location, thumbspng)
+                        oci = oci_eur if storage_location == 4 else oci_us
+                        img_url = DetectControllerViewV2.oci_object_url(oci, thumbspng)
                     else:
                         params = {'Key': thumbspng}
                         if region == 1:  # AWS国外
@@ -445,7 +447,8 @@ class DetectControllerViewV2(View):
                         if storage_location == 1:  # 阿里云oss
                             img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                         elif storage_location in [3, 4]:
-                            img_url = DetectControllerViewV2.oci_object_url(storage_location, thumbspng)
+                            oci = oci_eur if storage_location == 4 else oci_us
+                            img_url = DetectControllerViewV2.oci_object_url(oci, thumbspng)
                         else:
                             params = {'Key': thumbspng}
                             if region == 1:  # 国外AWS
@@ -478,14 +481,13 @@ class DetectControllerViewV2(View):
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
     @staticmethod
-    def oci_object_url(storage_location, obj_name):
+    def oci_object_url(oci, obj_name):
         """
         获取OCI对象存储URL 有效期5分钟
-        @param storage_location: 存储区域
+        @param oci:
         @param obj_name: 对象名称
         @return: url
         """
-        oci = OCIObjectStorage('eur' if storage_location == 4 else 'us')
         time_expires = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
         result = oci.get_preauthenticated_request_url(PUSH_BUCKET, 'ociPush', obj_name, time_expires)
         return result.full_path if result else ''
@@ -531,6 +533,8 @@ class DetectControllerViewV2(View):
                 region_name='cn-northwest-1'
             )
 
+            oci_eur = OCIObjectStorage('eur')
+            oci_us = OCIObjectStorage('us')
             # ai消息标识所有组合标签
             ai_all_event_type = EquipmentInfoService.get_all_comb_event_type()
             for equipment_info in equipment_info_qs:
@@ -547,7 +551,8 @@ class DetectControllerViewV2(View):
                     if storage_location == 1:  # 阿里云oss
                         img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                     elif storage_location in [3, 4]:
-                        img_url = DetectControllerViewV2.oci_object_url(storage_location, thumbspng)
+                        oci = oci_eur if storage_location == 4 else oci_us
+                        img_url = DetectControllerViewV2.oci_object_url(oci, thumbspng)
                     else:
                         params = {'Key': thumbspng}
                         if region == 1:  # AWS国外
@@ -604,7 +609,8 @@ class DetectControllerViewV2(View):
                         if storage_location == 1:  # 阿里云oss
                             img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                         elif storage_location in [3, 4]:
-                            img_url = DetectControllerViewV2.oci_object_url(storage_location, thumbspng)
+                            oci = oci_eur if storage_location == 4 else oci_us
+                            img_url = DetectControllerViewV2.oci_object_url(oci, thumbspng)
                         else:
                             params = {'Key': thumbspng}
                             if region == 1:  # 国外AWS