Browse Source

消息推送判断是否存储在OCI

zhangdongming 1 year ago
parent
commit
78627edc67
1 changed files with 24 additions and 0 deletions
  1. 24 0
      Controller/DetectControllerV2.py

+ 24 - 0
Controller/DetectControllerV2.py

@@ -1,3 +1,4 @@
+import datetime
 import json
 import json
 import time
 import time
 
 
@@ -13,6 +14,7 @@ from Ansjer.config import DETECT_PUSH_DOMAIN, DETECT_PUSH_DOMAINS, DETECT_PUSH_D
 from Model.models import Device_Info, Equipment_Info, UidSetModel, UidPushModel, CompanyModel, SysMsgModel, \
 from Model.models import Device_Info, Equipment_Info, UidSetModel, UidPushModel, CompanyModel, SysMsgModel, \
     AiService, VodBucketModel
     AiService, VodBucketModel
 from Object.ETkObject import ETkObject
 from Object.ETkObject import ETkObject
+from Object.OCIObjectStorage import OCIObjectStorage
 from Object.RedisObject import RedisObject
 from Object.RedisObject import RedisObject
 from Object.ResponseObject import ResponseObject
 from Object.ResponseObject import ResponseObject
 from Object.TokenObject import TokenObject
 from Object.TokenObject import TokenObject
@@ -20,6 +22,7 @@ from Object.utils import LocalDateTimeUtil
 from Service.CommonService import CommonService
 from Service.CommonService import CommonService
 from Service.EquipmentInfoService import EquipmentInfoService
 from Service.EquipmentInfoService import EquipmentInfoService
 from Service.VodHlsService import SplitVodHlsObject
 from Service.VodHlsService import SplitVodHlsObject
+from Ansjer.config import PUSH_BUCKET
 
 
 
 
 class DetectControllerViewV2(View):
 class DetectControllerViewV2(View):
@@ -384,6 +387,8 @@ class DetectControllerViewV2(View):
                     thumbspng = '{}/{}/{}.jpeg'.format(uid, channel, event_time)
                     thumbspng = '{}/{}/{}.jpeg'.format(uid, channel, event_time)
                     if storage_location == 1:  # 阿里云oss
                     if storage_location == 1:  # 阿里云oss
                         img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                         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)
                     else:
                     else:
                         params = {'Key': thumbspng}
                         params = {'Key': thumbspng}
                         if region == 1:  # AWS国外
                         if region == 1:  # AWS国外
@@ -439,6 +444,8 @@ class DetectControllerViewV2(View):
                         thumbspng = '{}/{}/{}_{}.jpeg'.format(uid, channel, event_time, i)
                         thumbspng = '{}/{}/{}_{}.jpeg'.format(uid, channel, event_time, i)
                         if storage_location == 1:  # 阿里云oss
                         if storage_location == 1:  # 阿里云oss
                             img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                             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)
                         else:
                         else:
                             params = {'Key': thumbspng}
                             params = {'Key': thumbspng}
                             if region == 1:  # 国外AWS
                             if region == 1:  # 国外AWS
@@ -470,6 +477,19 @@ class DetectControllerViewV2(View):
         except Exception as e:
         except Exception as e:
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
             return response.json(500, 'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
 
 
+    @staticmethod
+    def oci_object_url(storage_location, obj_name):
+        """
+        获取OCI对象存储URL 有效期5分钟
+        @param storage_location: 存储区域
+        @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 ''
+
     def do_transfer(self, request_dict, response, userID):
     def do_transfer(self, request_dict, response, userID):
         event_time = request_dict.get('eventTime', None)
         event_time = request_dict.get('eventTime', None)
         event_type = request_dict.get('eventType', None)
         event_type = request_dict.get('eventType', None)
@@ -526,6 +546,8 @@ class DetectControllerViewV2(View):
                     thumbspng = '{}/{}/{}.jpeg'.format(uid, channel, event_time)
                     thumbspng = '{}/{}/{}.jpeg'.format(uid, channel, event_time)
                     if storage_location == 1:  # 阿里云oss
                     if storage_location == 1:  # 阿里云oss
                         img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                         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)
                     else:
                     else:
                         params = {'Key': thumbspng}
                         params = {'Key': thumbspng}
                         if region == 1:  # AWS国外
                         if region == 1:  # AWS国外
@@ -581,6 +603,8 @@ class DetectControllerViewV2(View):
                         thumbspng = '{}/{}/{}_{}.jpeg'.format(uid, channel, event_time, i)
                         thumbspng = '{}/{}/{}_{}.jpeg'.format(uid, channel, event_time, i)
                         if storage_location == 1:  # 阿里云oss
                         if storage_location == 1:  # 阿里云oss
                             img_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
                             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)
                         else:
                         else:
                             params = {'Key': thumbspng}
                             params = {'Key': thumbspng}
                             if region == 1:  # 国外AWS
                             if region == 1:  # 国外AWS