62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
"""
|
|
文件系统相关 Pydantic 模式定义
|
|
"""
|
|
from typing import Literal, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class FileTreeItem(BaseModel):
|
|
"""文件树单个条目(文件 / 文件夹)"""
|
|
|
|
name: str = Field(..., description="文件 / 文件夹展示名称")
|
|
path: str = Field(
|
|
...,
|
|
description="基于 directory 的相对路径;文件夹末尾带 /,文件不带",
|
|
)
|
|
absolute: str = Field(..., description="服务器完整绝对物理路径")
|
|
type: str = Field(..., description="资源类型:directory / file")
|
|
ignored: bool = Field(..., description="是否属于被忽略的文件(如 git 忽略文件)")
|
|
|
|
|
|
class FileContentResponse(BaseModel):
|
|
"""文件内容预览响应"""
|
|
|
|
type: str = Field(
|
|
...,
|
|
description="内容类型:text(文本,可预览)/ binary(二进制,不可直接预览)",
|
|
)
|
|
content: str = Field(..., description="文件文本内容;二进制文件为空字符串")
|
|
|
|
|
|
class FileContentUpdateRequest(BaseModel):
|
|
"""文件内容修改请求"""
|
|
|
|
content: str = Field(..., description="文件新内容(UTF-8 文本)")
|
|
|
|
|
|
class FileContentUpdateResponse(BaseModel):
|
|
"""文件内容修改响应"""
|
|
|
|
success: bool = True
|
|
message: str = Field(..., description="操作结果说明")
|
|
path: str = Field(..., description="基于 directory 的相对文件路径")
|
|
absolute: str = Field(..., description="服务器完整绝对物理路径")
|
|
|
|
|
|
class FileCreateRequest(BaseModel):
|
|
"""文件 / 文件夹新建请求"""
|
|
|
|
type: Literal["file", "directory"] = Field(..., description="新建类型:file / directory")
|
|
content: Optional[str] = Field(default=None, description="文件初始内容(仅 type=file 生效)")
|
|
|
|
|
|
class FileOperationResponse(BaseModel):
|
|
"""文件操作(新建 / 删除)响应"""
|
|
|
|
success: bool = True
|
|
message: str = Field(..., description="操作结果说明")
|
|
path: str = Field(..., description="基于 directory 的相对路径")
|
|
absolute: str = Field(..., description="服务器完整绝对物理路径")
|
|
type: str = Field(..., description="资源类型:directory / file")
|