From 45d19d1cdd96827aa4a5daad1d60f05b16e74be0 Mon Sep 17 00:00:00 2001 From: HibiKier <775757368@qq.com> Date: Sun, 21 Jan 2024 22:27:03 +0800 Subject: [PATCH] =?UTF-8?q?feat=E2=9C=A8:=20=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=9F=A5=E7=9C=8Bapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/web_ui/api/tabs/system/__init__.py | 26 +++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/plugins/web_ui/api/tabs/system/__init__.py b/plugins/web_ui/api/tabs/system/__init__.py index 36755ff4..ec41df26 100644 --- a/plugins/web_ui/api/tabs/system/__init__.py +++ b/plugins/web_ui/api/tabs/system/__init__.py @@ -84,4 +84,28 @@ async def _(param: AddFile) -> Result: path.open('w') return Result.ok('新建文件成功!') except Exception as e: - return Result.warning_('新建文件失败: ' + str(e)) \ No newline at end of file + return Result.warning_('新建文件失败: ' + str(e)) + + +@router.post("/add_folder", dependencies=[authentication()], description="新建文件夹") +async def _(param: AddFile) -> Result: + path = (Path(param.parent) / param.name) if param.parent else Path(param.name) + if path.exists(): + return Result.warning_("文件夹已存在...") + try: + path.mkdir() + return Result.ok('新建文件夹成功!') + except Exception as e: + return Result.warning_('新建文件夹失败: ' + str(e)) + + +@router.get("/read_file", dependencies=[authentication()], description="读取文件") +async def _(full_path: str) -> Result: + path = Path(full_path) + if not path.exists(): + return Result.warning_("文件不存在...") + try: + text = path.read_text(encoding='utf-8') + return Result.ok(text) + except Exception as e: + return Result.warning_('新建文件夹失败: ' + str(e)) \ No newline at end of file