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

云存日志只记录上传和播放视频的操作

locky 3 жил өмнө
parent
commit
417a8da031
1 өөрчлөгдсөн 45 нэмэгдсэн , 43 устгасан
  1. 45 43
      Service/CloudLogs.py

+ 45 - 43
Service/CloudLogs.py

@@ -28,49 +28,51 @@ def batch_add_log_ctr(request, status_code):
     else:
         return
     request_path = request.path.strip().strip('/')
-    if 'storeplaylist' in request_path or 'signplaym3u8' in request_path:   # 只记录上传和播放视频的操作
-        user = MiscellService.get_access_name(request_dict)
-        uidToken = request_dict.get('uidToken', None)
-        utko = UidTokenObject(uidToken)
-        uid = utko.UID
-        if not uid:
-            uid = request_dict.get('uid', None)
-            if len(uid) > 50:
-                uid = jwt.decode(uid, OAUTH_ACCESS_TOKEN_SECRET, algorithms='HS256').get('uid', '')
-        clientIP = CommonService.get_ip_address(request)
-        # now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
-        # beijing = datetime.timezone(datetime.timedelta(hours=8))
-        # utc = datetime.timezone.utc  # 获取 UTC 的时区对象
-        # beijing_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(beijing)
-        now_time = time.time()
-        password = request_dict.get('userPwd', None)
-        if password is not None:
-            request_dict = dict(request_dict)
-            request_dict.pop('userPwd')
-        content = json.dumps(request_dict)
-        add_data = {
-            'user': user,
-            'ip': clientIP,
-            'uid': uid,
-            'url': request.META['SERVER_PROTOCOL'] + '-' + request.method + '-' + request.path,
-            'operation': request_path,
-            'time': now_time,
-            'content': content
-        }
-        print('add_data', add_data)
-        redisObj = RedisObject()
-        loggerData = json.dumps(add_data)
-        # print(loggerData)
-        if SERVER_TYPE == 'Ansjer.formal_settings':
-            logKey = 'logger'
-        else:
-            logKey = 'test_logger'
-        redisObj.rpush(name=logKey, val=loggerData)
-        # 判断redis列表长度
-        if redisObj.llen(name=logKey) > 100:
-            data_list = redisObj.lrange(logKey, 0, -1)
-            redisObj.del_data(key=logKey)
-            add_batch_log(data_list)
+    if 'cloudstorage' in request_path:
+        operation = request_dict.get('operation', None)
+        if operation == 'storeplaylist' or operation == 'signplaym3u8':     # 只记录上传和播放视频的操作
+            user = MiscellService.get_access_name(request_dict)
+            uidToken = request_dict.get('uidToken', None)
+            utko = UidTokenObject(uidToken)
+            uid = utko.UID
+            if not uid:
+                uid = request_dict.get('uid', None)
+                if len(uid) > 50:
+                    uid = jwt.decode(uid, OAUTH_ACCESS_TOKEN_SECRET, algorithms='HS256').get('uid', '')
+            clientIP = CommonService.get_ip_address(request)
+            # now_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(utc)
+            # beijing = datetime.timezone(datetime.timedelta(hours=8))
+            # utc = datetime.timezone.utc  # 获取 UTC 的时区对象
+            # beijing_time = datetime.datetime.utcnow().replace(tzinfo=utc).astimezone(beijing)
+            now_time = time.time()
+            password = request_dict.get('userPwd', None)
+            if password is not None:
+                request_dict = dict(request_dict)
+                request_dict.pop('userPwd')
+            content = json.dumps(request_dict)
+            add_data = {
+                'user': user,
+                'ip': clientIP,
+                'uid': uid,
+                'url': request.META['SERVER_PROTOCOL'] + '-' + request.method + '-' + request.path,
+                'operation': request_path,
+                'time': now_time,
+                'content': content
+            }
+            print('add_data', add_data)
+            redisObj = RedisObject()
+            loggerData = json.dumps(add_data)
+            # print(loggerData)
+            if SERVER_TYPE == 'Ansjer.formal_settings':
+                logKey = 'logger'
+            else:
+                logKey = 'test_logger'
+            redisObj.rpush(name=logKey, val=loggerData)
+            # 判断redis列表长度
+            if redisObj.llen(name=logKey) > 100:
+                data_list = redisObj.lrange(logKey, 0, -1)
+                redisObj.del_data(key=logKey)
+                add_batch_log(data_list)
 
 
 # 访问日志批量添加