mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
feat✨: 目录结构树编辑文件api
This commit is contained in:
parent
45d19d1cdd
commit
428f374a8c
@ -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))
|
||||
@ -51,3 +51,14 @@ class AddFile(BaseModel):
|
||||
"""父路径"""
|
||||
name: str
|
||||
"""新名称"""
|
||||
|
||||
|
||||
class SaveFile(BaseModel):
|
||||
|
||||
"""
|
||||
保存文件
|
||||
"""
|
||||
full_path: str
|
||||
"""全路径"""
|
||||
content: str
|
||||
"""内容"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user