From a1c4b8cb0d9de7f071e8f0414d1217356f854474 Mon Sep 17 00:00:00 2001 From: wuaho Date: Wed, 2 Jun 2021 13:46:12 +0800 Subject: [PATCH] update --- api/endpoints/apk_tools.py | 74 ++++++++++++++++++++++++++++++++++---- schemas/__init__.py | 2 +- schemas/channel.py | 4 +++ 3 files changed, 73 insertions(+), 7 deletions(-) diff --git a/api/endpoints/apk_tools.py b/api/endpoints/apk_tools.py index 521b55a..c101015 100644 --- a/api/endpoints/apk_tools.py +++ b/api/endpoints/apk_tools.py @@ -3,7 +3,7 @@ import json import os import time -from fastapi import APIRouter, File, BackgroundTasks +from fastapi import APIRouter, File, BackgroundTasks, UploadFile import schemas from core.config import settings @@ -30,20 +30,82 @@ router = APIRouter() # return resp -@router.post("/keystore") -async def keystore( - file: bytes = File(...) +# @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.post("/upload_file") +async def upload_file( + file_type: str, + file: UploadFile = File(...) ) -> schemas.Msg: - file_path = os.path.join(settings.ROOT_DIR, 'ApkTool/keystore/legu.keystore') + if file_type == 'mother_bag': + file_path = os.path.join(settings.ROOT_DIR, f'ApkTool/{file.filename}') + elif file_type == 'keystore': + file_path = os.path.join(settings.ROOT_DIR, f'ApkTool/keystore/{file.filename}') + else: + resp = schemas.Msg( + code=-1, + msg='文件类型错误', + data=file_type + ) + return resp + with open(file_path, 'wb') as f: - f.write(file) + 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.post("/delete_file") +async def delete_file( + data_in: schemas.DeleteFile, +) -> schemas.Msg: + file_path = data_in.file_path + if 'ApkTool' in file_path and os.path.exists(path=file_path): + os.remove(file_path) + + resp = schemas.Msg( + code=0, + msg='ok', + data=file_path + ) return resp diff --git a/schemas/__init__.py b/schemas/__init__.py index 11f9351..53258ae 100644 --- a/schemas/__init__.py +++ b/schemas/__init__.py @@ -1,3 +1,3 @@ # coding:utf-8 -from .channel import BaleCreate +from .channel import * from .msg import Msg \ No newline at end of file diff --git a/schemas/channel.py b/schemas/channel.py index 6330ee4..a1eccea 100644 --- a/schemas/channel.py +++ b/schemas/channel.py @@ -6,3 +6,7 @@ class BaleCreate(BaseModel): channel: dict dir: str id: int + + +class DeleteFile(BaseModel): + file_path: str