|
@@ -0,0 +1,86 @@
|
|
|
|
+# -*- encoding: utf-8 -*-
|
|
|
|
+"""
|
|
|
|
+@File : CronCloudPhotoController.py
|
|
|
|
+@Time : 2022/11/3 10:16
|
|
|
|
+@Author : stephen
|
|
|
|
+@Email : zhangdongming@asj6.wecom.work
|
|
|
|
+@Software: PyCharm
|
|
|
|
+"""
|
|
|
|
+import logging
|
|
|
|
+import time
|
|
|
|
+from Ansjer.config import ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, PUSH_BUCKET
|
|
|
|
+from django.db import transaction
|
|
|
|
+from django.views import View
|
|
|
|
+
|
|
|
|
+from Model.models import DeviceCloudPhotoInfo, Device_Info, CloudPhotoBGM
|
|
|
|
+from Object.AWS.AmazonS3Util import AmazonS3Util
|
|
|
|
+from Object.ResponseObject import ResponseObject
|
|
|
|
+from Object.TokenObject import TokenObject
|
|
|
|
+
|
|
|
|
+LOGGER = logging.getLogger('info')
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class CronCloudPhotoView(View):
|
|
|
|
+
|
|
|
|
+ def get(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.GET, request, operation)
|
|
|
|
+
|
|
|
|
+ def post(self, request, *args, **kwargs):
|
|
|
|
+ request.encoding = 'utf-8'
|
|
|
|
+ operation = kwargs.get('operation')
|
|
|
|
+ return self.validation(request.POST, request, operation)
|
|
|
|
+
|
|
|
|
+ def validation(self, request_dict, request, operation):
|
|
|
|
+ token = TokenObject(request.META.get('HTTP_AUTHORIZATION'))
|
|
|
|
+ lang = request_dict.get('lang', token.lang)
|
|
|
|
+ response = ResponseObject(lang)
|
|
|
|
+ if token.code != 0:
|
|
|
|
+ return response.json(token.code)
|
|
|
|
+ user_id = token.userID
|
|
|
|
+ if operation == 'get-photo':
|
|
|
|
+ return self.save_cloud_photo(user_id, request_dict, response)
|
|
|
|
+ else:
|
|
|
|
+ return response.json(404)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def save_cloud_photo(cls, user_id, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 保存云相册
|
|
|
|
+ """
|
|
|
|
+ try:
|
|
|
|
+ with transaction.atomic():
|
|
|
|
+ status = request_dict.get('status', None)
|
|
|
|
+ uid = request_dict.get('uid', None)
|
|
|
|
+ if not all([status, uid, user_id]):
|
|
|
|
+ return response(444)
|
|
|
|
+ device_info_qs = Device_Info.objects.filter(vodPrimaryUserID=user_id, uid=uid).values('primaryUserID')
|
|
|
|
+ if not device_info_qs.exists():
|
|
|
|
+ return response.json(14)
|
|
|
|
+ master_user_id = device_info_qs[0]['primaryUserID']
|
|
|
|
+ if master_user_id != '' and master_user_id != user_id:
|
|
|
|
+ return response.json(12)
|
|
|
|
+ now_time = int(time.time())
|
|
|
|
+ cloud_photo_qs = DeviceCloudPhotoInfo.objects.filter(uid=uid)
|
|
|
|
+ if not cloud_photo_qs.exists():
|
|
|
|
+ data = {'status': status, 'user_id': user_id, 'uid': uid, 'created_time': now_time,
|
|
|
|
+ 'updated_time': now_time}
|
|
|
|
+ DeviceCloudPhotoInfo.objects.create(**data)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ cloud_photo_qs.update(status=status, updated_time=now_time)
|
|
|
|
+ return response.json(0)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ LOGGER.info('异常详情,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
|
|
|
|
+ return response.json(500)
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_bgm_list(cls, request_dict, response):
|
|
|
|
+ """
|
|
|
|
+ 获取背景音乐列表
|
|
|
|
+ """
|
|
|
|
+ photo_bgm = CloudPhotoBGM.objects.filter(is_show=1).values('name')
|
|
|
|
+ if not photo_bgm.exists():
|
|
|
|
+ return response.json(0, [])
|
|
|
|
+ AmazonS3Util(ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME)
|
|
|
|
+ return response.json(0, [])
|