locky vor 10 Monaten
Ursprung
Commit
d228d25566
2 geänderte Dateien mit 28 neuen und 44 gelöschten Zeilen
  1. 24 33
      Controller/DetectController.py
  2. 4 11
      Service/DevicePushService.py

+ 24 - 33
Controller/DetectController.py

@@ -6,7 +6,7 @@ import oss2
 from django.http import JsonResponse
 from django.views.generic.base import View
 
-from AnsjerPush.config import CONFIG_INFO, CONFIG_CN, CONFIG_US, CONFIG_EUR, CONFIG_TEST
+from AnsjerPush.config import CONFIG_INFO, CONFIG_CN
 from AnsjerPush.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET
 from Object.RedisObject import RedisObject
 from Service.DevicePushService import DevicePushService
@@ -52,7 +52,6 @@ class NotificationView(View):
 
             V1_PUSH_LOGGER.info('旧移动侦测接口uid:{},时间戳:{},事件类型:{}'.format(uid, n_time, event_type))
 
-            is_st = int(is_st)
             event_type = int(event_type)
             pkey = '{}_{}_{}_ptl'.format(uid, event_type, channel)
             ykey = '{}_redis_qs'.format(uid)
@@ -116,18 +115,6 @@ class NotificationView(View):
             auth = oss2.Auth(OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET)
             bucket = oss2.Bucket(auth, 'oss-cn-shenzhen.aliyuncs.com', 'apg')
 
-            # 对象存储区域
-            # region: 国外(1), 国内(2)
-            # 测试/国内: 阿里云(1), 美洲: oci凤凰城(3), 欧洲: oci伦敦(4)
-            region = 1
-            if CONFIG_INFO == CONFIG_US or CONFIG_INFO == CONFIG_TEST:
-                storage_location = 3
-            elif CONFIG_INFO == CONFIG_EUR:
-                storage_location = 4
-            else:
-                region = 2
-                storage_location = 1
-
             # 推送相关参数
             push_kwargs = {
                 'uid': uid,
@@ -135,13 +122,11 @@ class NotificationView(View):
                 'event_type': event_type,
                 'n_time': n_time,
             }
-            params = {
-                'nickname': nickname, 'uid': uid, 'push_kwargs': push_kwargs, 'is_st': is_st, 'is_sys_msg': is_sys_msg,
-                'channel': channel, 'event_type': event_type, 'n_time': n_time, 'electricity': '', 'bucket': bucket,
-                'app_push': have_dkey, 'storage_location': storage_location, 'ai_type': 0, 'dealings_type': 0,
-                'detection': 0, 'device_type': 1, 'app_push_config': '', 'uid_set_push_list': uid_push_list,
-                'redis_obj': redis_obj
-            }
+            params = {'nickname': nickname, 'uid': uid, 'push_kwargs': push_kwargs, 'is_st': is_st,
+                      'is_sys_msg': is_sys_msg, 'channel': channel, 'event_type': event_type, 'n_time': n_time,
+                      'electricity': '', 'bucket': bucket, 'app_push': have_dkey, 'storage_location': 1, 'ai_type': 0,
+                      'dealings_type': 0, 'detection': 0, 'device_type': 1, 'app_push_config': '',
+                      'uid_set_push_list': uid_push_list, 'redis_obj': redis_obj}
 
             # 异步推送消息和保存数据
             push_thread = threading.Thread(
@@ -149,18 +134,24 @@ class NotificationView(View):
                 kwargs=params)
             push_thread.start()
 
-            # 获取图片上传链接
-            kwargs = {
-                'is_st': is_st,
-                'uid': uid,
-                'channel': channel,
-                'n_time': n_time,
-                'region': region,
-                'aws_s3_client': '',
-                'storage_location': storage_location,
-                'oss_bucket': bucket
-            }
-            res_data = DevicePushService.get_res_data(**kwargs)
+            res_data = {}
+            if is_st == '0' or is_st == '2':
+                res_data = {'code': 0, 'msg': 'success 0 or 2'}
+                return JsonResponse(status=200, data=res_data)
+
+            elif is_st == '1':
+                obj = '{}/{}/{}.jpeg'.format(uid, channel, n_time)
+                url = bucket.sign_url('PUT', obj, 3600)
+                res_data = {'code': 0, 'img_push': url, 'msg': 'success 1'}
+
+            elif is_st == '3':
+                img_url_list = []
+                for i in range(int(is_st)):
+                    obj = '{}/{}/{}_{}.jpeg'.format(uid, channel, n_time, i)
+                    url = bucket.sign_url('PUT', obj, 3600)
+                    img_url_list.append(url)
+
+                res_data = {'code': 0, 'img_url_list': img_url_list, 'msg': 'success 3'}
 
             V1_PUSH_LOGGER.info('旧推送接口响应,uid:{},n_time:{},事件类型:{},响应:{}'.
                                 format(uid, n_time, event_type, json.dumps(res_data)))

+ 4 - 11
Service/DevicePushService.py

@@ -838,7 +838,6 @@ class DevicePushService:
         storage_location = kwargs['storage_location']
         if is_st == 0 or is_st == 2:
             res_data['msg'] = 'success 0 or 2'
-
         elif is_st == 1:
             key_name = '{}/{}/{}.jpeg'.format(kwargs['uid'], kwargs['channel'], kwargs['n_time'])
             params = {'Key': key_name}
@@ -851,18 +850,16 @@ class DevicePushService:
                 # OCI
                 img_url = DevicePushService.create_oci_req_url(storage_location, params['Bucket'], key_name)
                 res_data['img_push'] = img_url
+                res_data['msg'] = 'success 1'
             elif storage_location == 2:
                 # AWS
                 img_url = DevicePushService.generate_s3_url(kwargs['aws_s3_client'], params)
-            elif storage_location == 1:
-                # 阿里云
-                img_url = kwargs['oss_bucket'].sign_url('PUT', key_name, 3600)
+                res_data['img_push'] = img_url
             else:
                 # 华为云
                 img_url = DevicePushService.create_obs_signed_url(key_name, 'PUT')
-            res_data['img_push'] = img_url
-            res_data['msg'] = 'success 1'
-
+                res_data['img_push'] = img_url
+                res_data['msg'] = 'success 1'
         elif is_st == 3:
             img_url_list = []
             if kwargs['region'] == 2:  # 2:国内
@@ -883,16 +880,12 @@ class DevicePushService:
                 elif storage_location == 2:
                     # AWS
                     img_url = DevicePushService.generate_s3_url(kwargs['aws_s3_client'], params)
-                elif storage_location == 1:
-                    # 阿里云
-                    img_url = kwargs['oss_bucket'].sign_url('PUT', key_name, 3600)
                 else:
                     # 华为云
                     img_url = DevicePushService.create_obs_signed_url(key_name, 'PUT')
                 img_url_list.append(img_url)
             res_data['img_url_list'] = img_url_list
             res_data['msg'] = 'success 3'
-
         return res_data
 
     @staticmethod