From 428f374a8c6418279b67757e66312304896f4d01 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Sun, 21 Jan 2024 22:34:05 +0800 Subject: [PATCH] =?UTF-8?q?feat=E2=9C=A8:=20=E7=9B=AE=E5=BD=95=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E6=A0=91=E7=BC=96=E8=BE=91=E6=96=87=E4=BB=B6api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/web_ui/api/tabs/system/__init__.py | 12 +++++++++++- plugins/web_ui/api/tabs/system/model.py | 11 +++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/plugins/web_ui/api/tabs/system/__init__.py b/plugins/web_ui/api/tabs/system/__init__.py index ec41df26..61430144 100644 --- a/plugins/web_ui/api/tabs/system/__init__.py +++ b/plugins/web_ui/api/tabs/system/__init__.py @@ -7,7 +7,7 @@ from fastapi import APIRouter from ....base_model import Result from ....utils import authentication, get_system_disk -from .model import AddFile, DeleteFile, DirFile, RenameFile +from .model import AddFile, DeleteFile, DirFile, RenameFile, SaveFile router = APIRouter(prefix="/system") @@ -107,5 +107,15 @@ async def _(full_path: str) -> Result: try: text = path.read_text(encoding='utf-8') return Result.ok(text) + except Exception as e: + return Result.warning_('新建文件夹失败: ' + str(e)) + +@router.post("/save_file", dependencies=[authentication()], description="读取文件") +async def _(param: SaveFile) -> Result: + path = Path(param.full_path) + try: + with path.open('w') as f: + f.write(param.content) + return Result.ok("更新成功!") except Exception as e: return Result.warning_('新建文件夹失败: ' + str(e)) \ No newline at end of file diff --git a/plugins/web_ui/api/tabs/system/model.py b/plugins/web_ui/api/tabs/system/model.py index af4f6209..b3b5a45f 100644 --- a/plugins/web_ui/api/tabs/system/model.py +++ b/plugins/web_ui/api/tabs/system/model.py @@ -51,3 +51,14 @@ class AddFile(BaseModel): """父路径""" name: str """新名称""" + + +class SaveFile(BaseModel): + + """ + 保存文件 + """ + full_path: str + """全路径""" + content: str + """内容"""