fix: aggregate resource api

This commit is contained in:
ibuler 2025-05-20 12:00:19 +08:00 committed by 老广
parent 4f19954640
commit 1364889083
2 changed files with 10 additions and 1 deletions

View File

@ -5,6 +5,7 @@ from urllib.parse import urlencode
import requests
from rest_framework.exceptions import NotFound, APIException
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from rest_framework.routers import DefaultRouter
from rest_framework.views import APIView
@ -63,6 +64,12 @@ class ProxyMixin(APIView):
data=body,
timeout=10,
)
return resp
content_type = resp.headers.get('Content-Type', '')
if 'application/json' in content_type:
data = resp.json()
else:
data = resp.text # 或者 bytesresp.content
return Response(data=data, status=resp.status_code)
except requests.RequestException as e:
raise APIException(f"Proxy request failed: {str(e)}")

View File

@ -7,6 +7,8 @@ from rest_framework.response import Response
from rest_framework.routers import DefaultRouter
from rest_framework.views import APIView
from .utils import get_full_resource_map
router = DefaultRouter()
BASE_URL = "http://localhost:8080"