mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-11 06:39:59 +08:00
feat✨: 目录结构树编辑查看api
This commit is contained in:
@@ -84,4 +84,28 @@ async def _(param: AddFile) -> Result:
|
|||||||
path.open('w')
|
path.open('w')
|
||||||
return Result.ok('新建文件成功!')
|
return Result.ok('新建文件成功!')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Result.warning_('新建文件失败: ' + str(e))
|
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))
|
||||||
Reference in New Issue
Block a user