diff --git a/apps/third/views.py b/apps/third/views.py index e7f5ca48..71071ce2 100644 --- a/apps/third/views.py +++ b/apps/third/views.py @@ -1,5 +1,5 @@ from rest_framework.exceptions import ParseError, APIException -from apps.third import tapis +from apps.third.tapis import dhapis, xxapis from apps.third.erros import TAPI_CODE_WRONG from apps.utils.dahua import dhClient from apps.utils.errors import XX_REQUEST_ERROR @@ -9,6 +9,7 @@ from rest_framework.views import APIView from rest_framework.permissions import IsAuthenticated from apps.utils.viewsets import CustomGenericViewSet from rest_framework.mixins import CreateModelMixin +from rest_framework.decorators import action from apps.third.serializers import RequestCommonSerializer # Create your views here. @@ -85,7 +86,7 @@ class XxCommonViewSet(CreateModelMixin, CustomGenericViewSet): vdata = serializer.validated_data if vdata.get('code', ''): try: - dhapi = tapis.dhapis[vdata['code']] + dhapi = dhapis[vdata['code']] except: raise ParseError(**TAPI_CODE_WRONG) vdata['url'] = dhapi['url'] @@ -97,6 +98,13 @@ class XxCommonViewSet(CreateModelMixin, CustomGenericViewSet): json=vdata.get('data', {})) return Response(res) + @action(methods=['get'], detail=False, permission_classes=[IsAuthenticated]) + def codes(self, request, pk=None): + """获取请求短标识 + + 获取请求短标识 + """ + return Response(xxapis) class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): """ @@ -111,7 +119,7 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): vdata = serializer.validated_data if vdata.get('code', ''): try: - xxapi = tapis.xxapis[vdata['code']] + xxapi = xxapis[vdata['code']] except: raise ParseError(**TAPI_CODE_WRONG) vdata['url'] = xxapi['url'] @@ -122,3 +130,11 @@ class DhCommonViewSet(CreateModelMixin, CustomGenericViewSet): params=vdata.get('params', {}), json=vdata.get('data', {})) return Response(res) + + @action(methods=['get'], detail=False, permission_classes=[IsAuthenticated]) + def codes(self, request, pk=None): + """获取请求短标识 + + 获取请求短标识 + """ + return Response(dhapis)