ezKit 3.0.45__tar.gz → 3.0.47__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ezkit-3.0.45/ezKit.egg-info → ezkit-3.0.47}/PKG-INFO +1 -1
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/fastapix.py +39 -11
- {ezkit-3.0.45 → ezkit-3.0.47/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.45 → ezkit-3.0.47}/setup.py +1 -1
- {ezkit-3.0.45 → ezkit-3.0.47}/LICENSE +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/MANIFEST.in +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/README.md +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/__init__.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/cipher.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/database.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/http.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/markdownx.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/stock.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit/utils.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/pyproject.toml +0 -0
- {ezkit-3.0.45 → ezkit-3.0.47}/setup.cfg +0 -0
|
@@ -8,10 +8,10 @@ from os import environ
|
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
from typing import Any, cast
|
|
10
10
|
|
|
11
|
-
from fastapi import FastAPI, Request
|
|
11
|
+
from fastapi import FastAPI, Request, Response as FastAPIResponse, status
|
|
12
12
|
from fastapi.exceptions import RequestValidationError
|
|
13
13
|
from fastapi.middleware.cors import CORSMiddleware
|
|
14
|
-
from fastapi.responses import JSONResponse
|
|
14
|
+
from fastapi.responses import FileResponse, JSONResponse
|
|
15
15
|
from loguru import logger
|
|
16
16
|
from pydantic import ValidationError
|
|
17
17
|
from sqlalchemy import and_, case, delete, insert, or_, select, true, update
|
|
@@ -142,10 +142,12 @@ class InterceptHandler(logging.Handler):
|
|
|
142
142
|
|
|
143
143
|
|
|
144
144
|
async def generic_api_execute(
|
|
145
|
-
operation: Callable[[Any], Awaitable[Any]],
|
|
145
|
+
operation: Callable[[Any], Any | Awaitable[Any]],
|
|
146
146
|
params_object: Any,
|
|
147
147
|
params_type: str = "text",
|
|
148
|
-
|
|
148
|
+
download_file: bool = False,
|
|
149
|
+
response: FastAPIResponse | None = None,
|
|
150
|
+
) -> JSONResponse | FileResponse | None:
|
|
149
151
|
"""Generic API Execution"""
|
|
150
152
|
|
|
151
153
|
# param: operation 函数
|
|
@@ -161,15 +163,21 @@ async def generic_api_execute(
|
|
|
161
163
|
# 即: 直接将 params_object 传递给 operation 函数
|
|
162
164
|
#
|
|
163
165
|
# params_type: text(默认), json, form
|
|
166
|
+
#
|
|
167
|
+
# download_file 和 response 必须同时存在
|
|
164
168
|
|
|
165
169
|
try:
|
|
166
170
|
|
|
167
|
-
if params_type not in {"text", "json", "form"}:
|
|
168
|
-
return Response(code=1001, message=f"Invalid parameter type: {params_type}")
|
|
169
|
-
|
|
170
171
|
if not isinstance(params_object, (str, Request)):
|
|
171
172
|
return Response(code=1001, message="Invalid parameter type")
|
|
172
173
|
|
|
174
|
+
if params_type not in {"text", "json", "form"}:
|
|
175
|
+
return Response(code=1001, message="Invalid parameter type")
|
|
176
|
+
|
|
177
|
+
# download_file 和 response 必须同时存在
|
|
178
|
+
if download_file and response is None:
|
|
179
|
+
return Response(code=1002, message="Missing response parameter")
|
|
180
|
+
|
|
173
181
|
if isinstance(params_object, Request):
|
|
174
182
|
if params_type == "json":
|
|
175
183
|
data = await params_object.json()
|
|
@@ -181,14 +189,28 @@ async def generic_api_execute(
|
|
|
181
189
|
data = params_object
|
|
182
190
|
|
|
183
191
|
if data in ("", {}, []) or (isinstance(data, FormData) and not data):
|
|
184
|
-
return Response(code=1002, message="Parameters cannot be empty")
|
|
185
192
|
|
|
186
|
-
|
|
193
|
+
# 处理下载文件错误
|
|
194
|
+
if download_file and response is not None:
|
|
195
|
+
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
196
|
+
return None
|
|
197
|
+
|
|
198
|
+
# 处理常规数据错误
|
|
199
|
+
return Response(code=1003, message="Parameters cannot be empty")
|
|
200
|
+
|
|
201
|
+
result = operation(data) if download_file else await operation(data)
|
|
187
202
|
|
|
188
203
|
if result is None:
|
|
189
|
-
return Response(code=1003, message="Execution failed. Check the parameters or service.")
|
|
190
204
|
|
|
191
|
-
|
|
205
|
+
# 处理下载文件错误
|
|
206
|
+
if download_file and response is not None:
|
|
207
|
+
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
# 处理常规数据错误
|
|
211
|
+
return Response(code=1004, message="Execution failed. Check the parameters or service.")
|
|
212
|
+
|
|
213
|
+
return cast(FileResponse, result) if download_file else cast(JSONResponse, Response(data=result))
|
|
192
214
|
|
|
193
215
|
except Exception as e:
|
|
194
216
|
|
|
@@ -197,6 +219,12 @@ async def generic_api_execute(
|
|
|
197
219
|
else:
|
|
198
220
|
logger.error(e)
|
|
199
221
|
|
|
222
|
+
# 处理下载文件错误
|
|
223
|
+
if download_file and response is not None:
|
|
224
|
+
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
225
|
+
return None
|
|
226
|
+
|
|
227
|
+
# 处理常规数据错误
|
|
200
228
|
return Response(code=400, message=str(e))
|
|
201
229
|
|
|
202
230
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|