Добавлен workspace API для файлового менеджера

Этот коммит содержится в:
Виктор
2026-05-11 23:27:17 +09:00
родитель 99093adfbc
Коммит 8d4faa0f0c
+62
Просмотреть файл
@@ -0,0 +1,62 @@
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from backend.file_workspace import (
WorkspaceSecurityError,
build_tree,
read_file,
save_file,
)
router = APIRouter(prefix='/api/files', tags=['workspace'])
class FilePathRequest(BaseModel):
path: str
class SaveFileRequest(BaseModel):
path: str
content: str
@router.post('/tree')
async def workspace_tree(payload: FilePathRequest):
try:
tree = build_tree(payload.path)
except WorkspaceSecurityError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
return {
'success': True,
'tree': tree,
}
@router.post('/read')
async def workspace_read(payload: FilePathRequest):
try:
content = read_file(payload.path)
except WorkspaceSecurityError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
return {
'success': True,
'content': content,
}
@router.post('/save')
async def workspace_save(payload: SaveFileRequest):
try:
result = save_file(payload.path, payload.content)
except WorkspaceSecurityError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
except Exception as exc:
raise HTTPException(status_code=500, detail=str(exc)) from exc
return result