Selaa lähdekoodia

修改推送列表返回数量

peng 1 vuosi sitten
vanhempi
commit
05691d8897
1 muutettua tiedostoa jossa 47 lisäystä ja 84 poistoa
  1. 47 84
      Controller/DetectControllerV2.py

+ 47 - 84
Controller/DetectControllerV2.py

@@ -368,35 +368,23 @@ class DetectControllerViewV2(View):
                 if p['is_st'] == 1:
                     thumbspng = '{uid}/{channel}/{time}.jpeg'.format(uid=devUid, channel=p['Channel'], time=eventTime)
                     if storage_location == 1:  # oss
-                        is_exist = oss_img_bucket.object_exists(thumbspng)
-                        if is_exist:
-                            response_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
-                            p['img'] = response_url
-                            p['img_list'] = [response_url]
-                        else:
-                            continue
+                        response_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
+                        p['img'] = response_url
+                        p['img_list'] = [response_url]
                     elif region == 2 and storage_location == 2:  # 2:国内,aws
-                        try:
-                            aws_s3_guonei.get_object(Bucket='push', Key=thumbspng)
-                            response_url = aws_s3_guonei.generate_presigned_url('get_object',
-                                                                                Params={'Bucket': 'push',
-                                                                                        'Key': thumbspng},
-                                                                                ExpiresIn=300)
-                            p['img'] = response_url
-                            p['img_list'] = [response_url]
-                        except aws_s3_guonei.exceptions.NoSuchKey:
-                            continue
+                        response_url = aws_s3_guonei.generate_presigned_url('get_object',
+                                                                            Params={'Bucket': 'push',
+                                                                                    'Key': thumbspng},
+                                                                            ExpiresIn=300)
+                        p['img'] = response_url
+                        p['img_list'] = [response_url]
                     elif region == 1 and storage_location == 2:  # 1:国外,aws
-                        try:
-                            aws_s3_guowai.get_object(Bucket='foreignpush', Key=thumbspng)
-                            response_url = aws_s3_guowai.generate_presigned_url('get_object',
-                                                                                Params={'Bucket': 'foreignpush',
-                                                                                        'Key': thumbspng},
-                                                                                ExpiresIn=300)
-                            p['img'] = response_url
-                            p['img_list'] = [response_url]
-                        except aws_s3_guowai.exceptions.NoSuchKey:
-                            continue
+                        response_url = aws_s3_guowai.generate_presigned_url('get_object',
+                                                                            Params={'Bucket': 'foreignpush',
+                                                                                    'Key': thumbspng},
+                                                                            ExpiresIn=300)
+                        p['img'] = response_url
+                        p['img_list'] = [response_url]
                 elif p['is_st'] == 2:
                     # 列表装载回放时间戳标记
                     split_vod_hls_obj = SplitVodHlsObject()
@@ -413,36 +401,24 @@ class DetectControllerViewV2(View):
                     ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=p['Channel'],
                                                                     etime=eventTime)
                     if storage_location == 1:  # oss
-                        is_exist = bucket.object_exists(ts)
-                        if is_exist:
-                            thumb0 = bucket.sign_url('GET', ts, 3600,
-                                                     params={'x-oss-process': 'video/snapshot,t_0000,w_700'})
-                            thumb1 = bucket.sign_url('GET', ts, 3600,
-                                                     params={'x-oss-process': 'video/snapshot,t_1000,w_700'})
-                            thumb2 = bucket.sign_url('GET', ts, 3600,
-                                                     params={'x-oss-process': 'video/snapshot,t_2000,w_700'})
-                            # thumb3 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_3000,w_700'})
-                            p['img_list'] = [thumb0, thumb1, thumb2]
-                        else:
-                            continue
+                        thumb0 = bucket.sign_url('GET', ts, 3600,
+                                                 params={'x-oss-process': 'video/snapshot,t_0000,w_700'})
+                        thumb1 = bucket.sign_url('GET', ts, 3600,
+                                                 params={'x-oss-process': 'video/snapshot,t_1000,w_700'})
+                        thumb2 = bucket.sign_url('GET', ts, 3600,
+                                                 params={'x-oss-process': 'video/snapshot,t_2000,w_700'})
+                        # thumb3 = bucket.sign_url('GET', ts, 3600, params={'x-oss-process': 'video/snapshot,t_3000,w_700'})
+                        p['img_list'] = [thumb0, thumb1, thumb2]
                     elif region == 2 and storage_location == 2:  # 2:国内,aws
-                        try:
-                            aws_s3_guonei.get_object(Bucket='push', Key=ts)
-                            thumb = aws_s3_guonei.generate_presigned_url('get_object',
-                                                                         Params={'Bucket': 'push', 'Key': ts},
-                                                                         ExpiresIn=3600)
-                            p['img_list'] = [thumb]
-                        except aws_s3_guonei.exceptions.NoSuchKey:
-                            continue
+                        thumb = aws_s3_guonei.generate_presigned_url('get_object',
+                                                                     Params={'Bucket': 'push', 'Key': ts},
+                                                                     ExpiresIn=3600)
+                        p['img_list'] = [thumb]
                     elif region == 1 and storage_location == 2:  # 1:国外,aws
-                        try:
-                            aws_s3_guowai.get_object(Bucket='foreignpush', Key=ts)
-                            thumb = aws_s3_guowai.generate_presigned_url('get_object',
-                                                                         Params={'Bucket': 'foreignpush', 'Key': ts},
-                                                                         ExpiresIn=3600)
-                            p['img_list'] = [thumb]
-                        except aws_s3_guowai.exceptions.NoSuchKey:
-                            continue
+                        thumb = aws_s3_guowai.generate_presigned_url('get_object',
+                                                                     Params={'Bucket': 'foreignpush', 'Key': ts},
+                                                                     ExpiresIn=3600)
+                        p['img_list'] = [thumb]
                 elif p['is_st'] == 3 or p['is_st'] == 4:
                     # 列表装载回放时间戳标记
                     p['img_list'] = []
@@ -450,36 +426,23 @@ class DetectControllerViewV2(View):
                         thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=p['Channel'],
                                                                               time=eventTime, st=i)
                         if storage_location == 1:  # oss
-                            is_exist = oss_img_bucket.object_exists(thumbspng)
-                            if is_exist:
-                                img = oss_img_bucket.sign_url('GET', thumbspng, 300)
-                                p['img_list'].append(img)
-                            else:
-                                break
+                            img = oss_img_bucket.sign_url('GET', thumbspng, 300)
+                            p['img_list'].append(img)
                         elif region == 2 and storage_location == 2:  # 2:国内,aws
-                            try:
-                                aws_s3_guonei.get_object(Bucket='push', Key=thumbspng)
-                                response_url = aws_s3_guonei.generate_presigned_url('get_object',
-                                                                                    Params={'Bucket': 'push',
-                                                                                            'Key': thumbspng},
-                                                                                    ExpiresIn=300)
-                                img = response_url
-                                p['img_list'].append(img)
-                            except aws_s3_guonei.exceptions.NoSuchKey:
-                                break
+                            response_url = aws_s3_guonei.generate_presigned_url('get_object',
+                                                                                Params={'Bucket': 'push',
+                                                                                        'Key': thumbspng},
+                                                                                ExpiresIn=300)
+                            img = response_url
+                            p['img_list'].append(img)
                         elif region == 1 and storage_location == 2:  # 1:国外,aws
-                            try:
-                                aws_s3_guowai.get_object(Bucket='foreignpush', Key=thumbspng)
-                                response_url = aws_s3_guowai.generate_presigned_url('get_object',
-                                                                                    Params={'Bucket': 'foreignpush',
-                                                                                            'Key': thumbspng},
-                                                                                    ExpiresIn=300)
-                                img = response_url
-                                p['img_list'].append(img)
-                            except aws_s3_guowai.exceptions.NoSuchKey:
-                                break
-                    if not p['img_list']:
-                        continue
+                            response_url = aws_s3_guowai.generate_presigned_url('get_object',
+                                                                                Params={'Bucket': 'foreignpush',
+                                                                                        'Key': thumbspng},
+                                                                                ExpiresIn=300)
+                            img = response_url
+                            p['img_list'].append(img)
+
                 if devUid in uid_type_dict.keys():
                     p['uid_type'] = uid_type_dict[devUid]['type']
                     p['devNickName'] = uid_type_dict[devUid]['NickName']
@@ -494,7 +457,7 @@ class DetectControllerViewV2(View):
                 if EquipmentInfoService.is_combo_tag(p['eventType'], p['eventTag']):
                     p['ai_event_type_list'] += EquipmentInfoService.get_combo_types(p['eventType'], p['eventTag'])
                 res.append(p)
-            return response.json(0, {'datas': res, 'count': len(res)})
+            return response.json(0, {'datas': res, 'count': count})
         except Exception as e:
             print(repr(e))
             return response.json(474)