1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- # Create your views here.
- from rest_framework.views import APIView
- from rest_framework.viewsets import ModelViewSet
- from background.Object import AmazonS3Util
- from background.serializers import ProductInfoSerializer, VideoInSerializer, QuickStartInfoSerializer, \
- UpgradeFirmwareInfoSerializer
- from background.models import ProductInfo, VideoInfo, QuickStartInfo, UpgradeFirmwareInfo
- from rest_framework.response import Response
- class ProductInfoSet(ModelViewSet):
- queryset = ProductInfo.objects.all()
- serializer_class = ProductInfoSerializer
- class VideoInfoSet(ModelViewSet):
- queryset = VideoInfo.objects.all()
- serializer_class = VideoInSerializer
- filterset_fields = ['id', 'product_info_id', 'title']
- class QuickStartInfoSet(ModelViewSet):
- queryset = QuickStartInfo.objects.all()
- serializer_class = QuickStartInfoSerializer
- filterset_fields = ['id', 'product_info_id', 'title']
- class UpgradeFirmwareInfoSet(ModelViewSet):
- queryset = UpgradeFirmwareInfo.objects.all()
- serializer_class = UpgradeFirmwareInfoSerializer
- filterset_fields = ['id', 'product_info_id', 'title']
- class GetUploadUrlView(APIView):
- def get(self, request):
- file_name = request.GET.get('file_name', None)
- file_type = request.GET.get('file_type', None)
- if not all([file_name]):
- return Response({'code': 444, 'result': {'error_msg': 'file_name参数有误'}})
- try:
- s3_obj = AmazonS3Util()
- if file_type == '1': # 视频
- key_name = 'vsees/video_file/{file_name}'.format(file_name=file_name)
- elif file_type == '2': # 说明书
- key_name = 'vsees/quick_start_file/{file_name}'.format(file_name=file_name)
- elif file_type == '3': # 升级文件
- key_name = 'vsees/upgrade_firmware_file/{file_name}'.format(file_name=file_name)
- else:
- return Response({'code': 444, 'result': {'error_msg': 'file_type参数有误'}})
- bucket_name = 'ansjerfilemanager'
- upload_url = s3_obj.generate_put_obj_url(bucket_name, key_name)
- return Response({'code': 0, 'result': {'uploadUrl': upload_url}})
- except Exception as e:
- return Response(
- {'code': 500, 'result': {'error_line:{}, error_msg:{}'.format(e.__traceback__.tb_lineno, repr(e))}})
|