Selaa lähdekoodia

Merge branch 'dev' into lang

lang 3 vuotta sitten
vanhempi
commit
7411acfea7

+ 35 - 3
AdminController/VersionManagementController.py

@@ -4,10 +4,12 @@ import os
 import hashlib
 import time
 
+import boto3
+import botocore
 from django.db import transaction
 from django.views.generic.base import View
 
-from Ansjer.config import BASE_DIR
+from Ansjer.config import BASE_DIR, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY
 from Object.TokenObject import TokenObject
 from Object.ResponseObject import ResponseObject
 from Service.CommonService import CommonService
@@ -66,7 +68,8 @@ class VersionManagement(View):
                 return self.getPcInfoList(request_dict, response)
             elif operation == 'editPcVersion':
                 return self.editPcVersion(request_dict, response)
-
+            elif operation == 'deletePcInfo':
+                return self.deletePcInfo(request_dict, response)
             else:
                 return response.json(404)
 
@@ -566,7 +569,7 @@ class VersionManagement(View):
 
         if not pc_info_id:
             return response.json(444)
-        pc_version = 1 if pc_version == 'true' else 0
+
         try:
             pc_info_qs = Pc_Info.objects.filter(id=pc_info_id)
             if not pc_info_qs.exists():
@@ -591,3 +594,32 @@ class VersionManagement(View):
         except Exception as e:
             print(e)
             return response.json(500, repr(e))
+
+    def deletePcInfo(self, request_dict, response):
+        print('request_dict:', request_dict)
+        pc_info_id = request_dict.get('id', None)
+
+        try:
+            if not pc_info_id:
+                return response.json(444)
+            pc_info_qs = Pc_Info.objects.filter(id=pc_info_id)
+            if not pc_info_qs.exists():
+                return response.json(173)
+            # 删除存储桶的文件
+            Key = pc_info_qs.values('download_link')[0]['download_link']
+            pc_info_qs.delete()
+            aws_s3_client = boto3.client(
+                's3',
+                region_name='cn-northwest-1',
+                aws_access_key_id=AWS_ACCESS_KEY_ID[0],
+                aws_secret_access_key=AWS_SECRET_ACCESS_KEY[0],
+                config=botocore.client.Config(signature_version='s3v4'),
+            )
+
+            try:
+                aws_s3_client.delete_object(Bucket='pc-package', Key=Key)
+            finally:
+                return response.json(0)
+        except Exception as e:
+            print(e)
+            return response.json(500, repr(e))

+ 1 - 0
Ansjer/urls.py

@@ -208,6 +208,7 @@ urlpatterns = [
     # 删除云存视频
     # path('cv/del', CloudVod.deleteVodHls),
     path('cv/del', CloudStorage.deleteVodHls),
+    path('cv/delCloudLog', CloudStorage.deleteCloudLog),
     path('cv/updateExpiredUidBucket', CloudStorage.updateExpiredUidBucket),
     path('cv/updateUnusedUidBucket', CloudStorage.updateUnusedUidBucket),
     url(r'^equipment/judge', EquipmentManager.judgeInterface),

+ 12 - 2
Controller/CloudStorage.py

@@ -40,7 +40,7 @@ from Ansjer.config import OSS_STS_ACCESS_KEY, OSS_STS_ACCESS_SECRET, OSS_ROLE_AR
 from Controller.CheckUserData import DataValid
 from Model.models import Device_Info, Order_Model, Store_Meal, VodHlsModel, OssCrdModel, UID_Bucket, StsCrdModel, \
     ExperienceContextModel, Pay_Type, CDKcontextModel, Device_User, SysMassModel, SysMsgModel, UidPushModel, \
-    Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel
+    Unused_Uid_Meal, UIDMainUser, UserModel, PromotionRuleModel, VideoPlaybackTimeModel, CloudLogModel
 from Object.AWS.S3Email import S3Email
 from Object.AliPayObject import AliPayObject
 from Object.AliSmsObject import AliSmsObject
@@ -1940,4 +1940,14 @@ def updateUnusedUidBucket(request):
         except Exception:
             continue
     # UID_Bucket.objects.filter(id__in=list(id_list)).update(use_status=2)  # 更新过期云存关联套餐状态
-    return response.json(0)
+    return response.json(0)
+
+# 删除三个月之前的cloud_log数据
+def deleteCloudLog(request):
+    response = ResponseObject()
+    delTime = int(time.time()) - 3 * 30 * 24 * 60 * 60  # 保留3个月的数据
+    for i in range(5):
+        cloud_log_qs = CloudLogModel.objects.filter(time__lte=delTime)[0:10000]
+        id_list = cloud_log_qs.values_list('id', flat=True)
+        CloudLogModel.objects.filter(id__in=list(id_list)).delete()
+    return response.json(0)

+ 1 - 1
Controller/DeviceLogController.py

@@ -49,7 +49,7 @@ class DeviceLogView(View):
 
         try:
             device_id = uid if uid else serial_number
-            # device_id = CommonService.decode_data(device_id)
+            device_id = CommonService.decode_data(device_id)
             put_url_list = []
             for num in range(file_num):
                 # 日志文件名

+ 2 - 3
Controller/UserController.py

@@ -658,6 +658,7 @@ class refreshTokenViewV3(TemplateView):
         try:
             # token检验
             tko = TokenObject(token)
+            res = tko.refresh()  # 更新refresh_token
             if tko.code != 0:
                 return response.json(tko.code)
             userID = tko.userID
@@ -673,11 +674,9 @@ class refreshTokenViewV3(TemplateView):
                 user_qs = Device_User.objects.filter(userID=userID).values('password')
                 if not user_qs.exists():
                     return response.json(104)
-                if not check_password(password, user_qs[0].password):
+                if not check_password(password, list(user_qs)[0]['password']):
                     return response.json(111)
 
-            res = tko.refresh()     # 更新refresh_token
-
             # 更新用户扩展信息语言
             user_ex_qs = UserExModel.objects.filter(userID_id=userID)
             if user_ex_qs.exists():

+ 2 - 0
Object/TokenObject.py

@@ -148,6 +148,8 @@ class TokenObject:
             userID = res.get('userID', '')
             user = res.get('user', '')
             lang = self.lang
+            self.userID = userID
+            self.user = user
             refreshRes = self.generate(data={'userID': userID, 'lang': lang, 'user': user})
             return refreshRes
 

+ 1 - 1
Service/CloudLogs.py

@@ -28,7 +28,7 @@ def batch_add_log_ctr(request, status_code):
     else:
         return
     request_path = request.path.strip().strip('/')
-    if 'cloudstorage' in request_path :
+    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)