48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""
|
||
文件系统操作相关的 Pydantic Schema
|
||
"""
|
||
from pydantic import BaseModel, Field
|
||
from typing import Optional, List
|
||
|
||
|
||
class FileTreeNode(BaseModel):
|
||
"""文件树节点 Schema"""
|
||
title: str = Field(..., description="节点标题(文件/文件夹名)")
|
||
key: str = Field(..., description="节点唯一键(相对路径)")
|
||
isLeaf: bool = Field(..., description="是否叶子节点")
|
||
children: Optional[List['FileTreeNode']] = Field(None, description="子节点")
|
||
|
||
class Config:
|
||
from_attributes = True
|
||
|
||
|
||
# 支持递归引用
|
||
FileTreeNode.model_rebuild()
|
||
|
||
|
||
class FileContentRequest(BaseModel):
|
||
"""文件内容请求 Schema"""
|
||
path: str = Field(..., description="文件相对路径")
|
||
|
||
|
||
class FileSaveRequest(BaseModel):
|
||
"""文件保存请求 Schema"""
|
||
path: str = Field(..., description="文件相对路径")
|
||
content: str = Field(..., description="文件内容")
|
||
|
||
|
||
class FileOperateRequest(BaseModel):
|
||
"""文件操作请求 Schema"""
|
||
action: str = Field(..., description="操作类型:rename|delete|create_dir|create_file")
|
||
path: str = Field(..., description="当前路径")
|
||
new_path: Optional[str] = Field(None, description="新路径(重命名时使用)")
|
||
content: Optional[str] = Field(None, description="文件内容(创建文件时使用)")
|
||
|
||
|
||
class FileUploadResponse(BaseModel):
|
||
"""文件上传响应 Schema"""
|
||
filename: str = Field(..., description="文件名")
|
||
path: str = Field(..., description="文件相对路径")
|
||
url: str = Field(..., description="文件访问URL")
|
||
size: int = Field(..., description="文件大小(字节)")
|