ezKit 3.0.45__tar.gz → 3.0.46__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.46}/PKG-INFO +1 -1
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/fastapix.py +28 -6
- {ezkit-3.0.45 → ezkit-3.0.46/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.45 → ezkit-3.0.46}/setup.py +1 -1
- {ezkit-3.0.45 → ezkit-3.0.46}/LICENSE +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/MANIFEST.in +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/README.md +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/__init__.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/cipher.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/database.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/http.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/markdownx.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/stock.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit/utils.py +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/pyproject.toml +0 -0
- {ezkit-3.0.45 → ezkit-3.0.46}/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 函数
|
|
@@ -181,14 +183,28 @@ async def generic_api_execute(
|
|
|
181
183
|
data = params_object
|
|
182
184
|
|
|
183
185
|
if data in ("", {}, []) or (isinstance(data, FormData) and not data):
|
|
186
|
+
|
|
187
|
+
# 处理下载文件错误
|
|
188
|
+
if download_file and response is not None:
|
|
189
|
+
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
190
|
+
return None
|
|
191
|
+
|
|
192
|
+
# 处理常规数据错误
|
|
184
193
|
return Response(code=1002, message="Parameters cannot be empty")
|
|
185
194
|
|
|
186
|
-
result = await operation(data)
|
|
195
|
+
result = operation(data) if download_file else await operation(data)
|
|
187
196
|
|
|
188
197
|
if result is None:
|
|
198
|
+
|
|
199
|
+
# 处理下载文件错误
|
|
200
|
+
if download_file and response is not None:
|
|
201
|
+
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
202
|
+
return None
|
|
203
|
+
|
|
204
|
+
# 处理常规数据错误
|
|
189
205
|
return Response(code=1003, message="Execution failed. Check the parameters or service.")
|
|
190
206
|
|
|
191
|
-
return Response(data=result)
|
|
207
|
+
return cast(FileResponse, result) if download_file else cast(JSONResponse, Response(data=result))
|
|
192
208
|
|
|
193
209
|
except Exception as e:
|
|
194
210
|
|
|
@@ -197,6 +213,12 @@ async def generic_api_execute(
|
|
|
197
213
|
else:
|
|
198
214
|
logger.error(e)
|
|
199
215
|
|
|
216
|
+
# 处理下载文件错误
|
|
217
|
+
if download_file and response is not None:
|
|
218
|
+
response.status_code = status.HTTP_400_BAD_REQUEST
|
|
219
|
+
return None
|
|
220
|
+
|
|
221
|
+
# 处理常规数据错误
|
|
200
222
|
return Response(code=400, message=str(e))
|
|
201
223
|
|
|
202
224
|
|
|
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
|