diff --git a/api/endpoints/apk_tools.py b/api/endpoints/apk_tools.py index a03ca32..6d9df14 100644 --- a/api/endpoints/apk_tools.py +++ b/api/endpoints/apk_tools.py @@ -12,56 +12,9 @@ from utils import * router = APIRouter() -# -# @router.post("/channel.json") -# async def channel.json( -# data_in: schemas.BaleCreate -# ) -> schemas.Msg: -# file = os.path.join(settings.ROOT_DIR, 'ApkTool/channel.json') -# with open(file, 'w') as f: -# json.dump(data_in.channel.json, f) -# -# resp = schemas.Msg( -# code=0, -# msg='ok', -# data=data_in -# ) -# -# return resp - - -# @router.post("/keystore") -# async def keystore( -# file: bytes = File(...) -# ) -> schemas.Msg: -# file_path = os.path.join(settings.ROOT_DIR, 'ApkTool/keystore/legu.keystore') -# with open(file_path, 'wb') as f: -# f.write(file) -# -# resp = schemas.Msg( -# code=0, -# msg='ok', -# data=file_path -# ) -# -# return resp -# -# -# @router.post("/mother_bag") -# async def mother_bag( -# file: UploadFile = File(...) -# ) -> schemas.Msg: -# file_path = os.path.join(settings.ROOT_DIR, f'ApkTool/{file.filename}') -# with open(file_path, 'wb') as f: -# for i in iter(lambda: file.file.read(1024 * 1024 * 10), b''): -# f.write(i) -# -# resp = schemas.Msg( -# code=0, -# msg='ok', -# data=file_path -# ) -# return resp +@router.get("/test") +async def test(): + 1 / 0 @router.post("/upload_file") diff --git a/main.py b/main.py index f4c76a2..e05ad26 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import uvicorn from fastapi import FastAPI from fastapi.exceptions import RequestValidationError -from fastapi import Response +from starlette.responses import Response from starlette.middleware.cors import CORSMiddleware import schemas @@ -21,14 +21,14 @@ app.add_middleware( ) -# @app.exception_handler(RequestValidationError) -# async def validation_exception_handler(request, exc): -# return Response(schemas.Msg(code='-1', msg='服务器错误', data=str(exc)), status_code=200) -# -# -# @app.exception_handler(Exception) -# async def http_exception_handler(request, exc): -# return Response(schemas.Msg(code='-1', msg='服务器错误'), status_code=200) +@app.exception_handler(RequestValidationError) +async def validation_exception_handler(request, exc): + return Response(schemas.Msg(code=-1, msg='服务器错误', data=str(exc)).json(), status_code=200) + + +@app.exception_handler(Exception) +async def http_exception_handler(request, exc): + return Response(schemas.Msg(code=-1, msg='服务器错误', data=str(exc)).json(), status_code=200) if __name__ == '__main__':