Spaces:
Building
Building
Update admin_routes.py
Browse files- admin_routes.py +19 -6
admin_routes.py
CHANGED
@@ -114,26 +114,26 @@ class APICreate(BaseModel):
|
|
114 |
name: str
|
115 |
url: str
|
116 |
method: str = "POST"
|
117 |
-
headers:
|
118 |
-
body_template:
|
119 |
timeout_seconds: int = 10
|
120 |
retry: Dict[str, Any] = Field(default_factory=lambda: {"retry_count": 3, "backoff_seconds": 2, "strategy": "static"})
|
121 |
proxy: Optional[str] = None
|
122 |
auth: Optional[Dict[str, Any]] = None
|
123 |
response_prompt: Optional[str] = None
|
124 |
-
response_mappings: List[Dict[str, Any]] = []
|
125 |
|
126 |
class APIUpdate(BaseModel):
|
127 |
url: str
|
128 |
method: str
|
129 |
-
headers:
|
130 |
-
body_template:
|
131 |
timeout_seconds: int
|
132 |
retry: Dict[str, Any]
|
133 |
proxy: Optional[str]
|
134 |
auth: Optional[Dict[str, Any]]
|
135 |
response_prompt: Optional[str]
|
136 |
-
response_mappings: List[Dict[str, Any]] = []
|
137 |
last_update_date: str
|
138 |
|
139 |
class TestRequest(BaseModel):
|
@@ -963,6 +963,19 @@ async def create_api(api: APICreate, username: str = Depends(verify_token)):
|
|
963 |
"""Create new API"""
|
964 |
config = load_config()
|
965 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
966 |
# Check duplicate name
|
967 |
existing = [a for a in config.get("apis", []) if a["name"] == api.name]
|
968 |
if existing:
|
|
|
114 |
name: str
|
115 |
url: str
|
116 |
method: str = "POST"
|
117 |
+
headers: str = "{}" # JSON string olarak
|
118 |
+
body_template: str = "{}" # JSON string olarak
|
119 |
timeout_seconds: int = 10
|
120 |
retry: Dict[str, Any] = Field(default_factory=lambda: {"retry_count": 3, "backoff_seconds": 2, "strategy": "static"})
|
121 |
proxy: Optional[str] = None
|
122 |
auth: Optional[Dict[str, Any]] = None
|
123 |
response_prompt: Optional[str] = None
|
124 |
+
response_mappings: List[Dict[str, Any]] = []
|
125 |
|
126 |
class APIUpdate(BaseModel):
|
127 |
url: str
|
128 |
method: str
|
129 |
+
headers: str # JSON string olarak
|
130 |
+
body_template: str # JSON string olarak
|
131 |
timeout_seconds: int
|
132 |
retry: Dict[str, Any]
|
133 |
proxy: Optional[str]
|
134 |
auth: Optional[Dict[str, Any]]
|
135 |
response_prompt: Optional[str]
|
136 |
+
response_mappings: List[Dict[str, Any]] = []
|
137 |
last_update_date: str
|
138 |
|
139 |
class TestRequest(BaseModel):
|
|
|
963 |
"""Create new API"""
|
964 |
config = load_config()
|
965 |
|
966 |
+
# Validate JSON strings
|
967 |
+
try:
|
968 |
+
json.loads(api.headers)
|
969 |
+
json.loads(api.body_template)
|
970 |
+
if api.auth and api.auth.get("token_request_body"):
|
971 |
+
if isinstance(api.auth["token_request_body"], str):
|
972 |
+
json.loads(api.auth["token_request_body"])
|
973 |
+
if api.auth and api.auth.get("token_refresh_body"):
|
974 |
+
if isinstance(api.auth["token_refresh_body"], str):
|
975 |
+
json.loads(api.auth["token_refresh_body"])
|
976 |
+
except json.JSONDecodeError as e:
|
977 |
+
raise HTTPException(status_code=400, detail=f"Invalid JSON format: {str(e)}")
|
978 |
+
|
979 |
# Check duplicate name
|
980 |
existing = [a for a in config.get("apis", []) if a["name"] == api.name]
|
981 |
if existing:
|