Эх сурвалжийг харах

推送列表不显示无图片

peng 1 жил өмнө
parent
commit
ea0b2529e1

+ 27 - 13
Controller/DetectControllerV2.py

@@ -368,9 +368,13 @@ 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
-                        response_url = oss_img_bucket.sign_url('GET', thumbspng, 300)
-                        p['img'] = response_url
-                        p['img_list'] = [response_url]
+                        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
                     elif region == 2 and storage_location == 2:  # 2:国内,aws
                         response_url = aws_s3_guonei.generate_presigned_url('get_object',
                                                                             Params={'Bucket': 'push', 'Key': thumbspng},
@@ -401,14 +405,18 @@ class DetectControllerViewV2(View):
                     ts = '{uid}/vod{channel}/{etime}/ts0.ts'.format(uid=devUid, channel=p['Channel'],
                                                                     etime=eventTime)
                     if storage_location == 1:  # oss
-                        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]
+                        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
                     elif region == 2 and storage_location == 2:  # 2:国内,aws
                         thumb = aws_s3_guonei.generate_presigned_url('get_object',
                                                                      Params={'Bucket': 'push', 'Key': ts},
@@ -426,8 +434,12 @@ class DetectControllerViewV2(View):
                         thumbspng = '{uid}/{channel}/{time}_{st}.jpeg'.format(uid=devUid, channel=p['Channel'],
                                                                               time=eventTime, st=i)
                         if storage_location == 1:  # oss
-                            img = oss_img_bucket.sign_url('GET', thumbspng, 300)
-                            p['img_list'].append(img)
+                            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
                         elif region == 2 and storage_location == 2:  # 2:国内,aws
                             response_url = aws_s3_guonei.generate_presigned_url('get_object',
                                                                                 Params={'Bucket': 'push',
@@ -442,6 +454,8 @@ class DetectControllerViewV2(View):
                                                                                 ExpiresIn=300)
                             img = response_url
                             p['img_list'].append(img)
+                    if not p['img_list']:
+                        continue
                 if devUid in uid_type_dict.keys():
                     p['uid_type'] = uid_type_dict[devUid]['type']
                     p['devNickName'] = uid_type_dict[devUid]['NickName']