feat: 目录结构树编辑文件api

This commit is contained in:
HibiKier 2024-01-21 22:34:05 +08:00
parent 45d19d1cdd
commit 428f374a8c
2 changed files with 22 additions and 1 deletions

View File

@ -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))

View File

@ -51,3 +51,14 @@ class AddFile(BaseModel):
"""父路径"""
name: str
"""新名称"""
class SaveFile(BaseModel):
"""
保存文件
"""
full_path: str
"""全路径"""
content: str
"""内容"""