feat: add fs-backend service
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
数据模式模块初始化
|
||||
"""
|
||||
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
文件系统相关 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")
|
||||
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
Pydantic 模式定义
|
||||
"""
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
import re
|
||||
|
||||
|
||||
class ProjectCreateRequest(BaseModel):
|
||||
"""项目创建请求"""
|
||||
|
||||
project_name: str = Field(..., description="项目文件夹名称", min_length=1, max_length=100)
|
||||
|
||||
@field_validator("project_name")
|
||||
@classmethod
|
||||
def validate_project_name(cls, v: str) -> str:
|
||||
"""
|
||||
验证项目名:
|
||||
- 仅允许中英文、数字、下划线、横杠
|
||||
- 禁止路径逃逸字符
|
||||
"""
|
||||
# 检查是否包含路径逃逸字符
|
||||
if ".." in v or "/" in v or "\\" in v:
|
||||
raise ValueError("项目名称不能包含路径逃逸字符 (../ 或 / 或 \\)")
|
||||
|
||||
# 验证项目名称格式:仅允许中英文、数字、下划线、横杠
|
||||
pattern = r"^[\w一-龥\-]+$"
|
||||
if not re.match(pattern, v):
|
||||
raise ValueError("项目名称仅允许包含中英文、数字、下划线、横杠")
|
||||
|
||||
return v
|
||||
|
||||
|
||||
class ProjectCreateResponse(BaseModel):
|
||||
"""项目创建响应"""
|
||||
|
||||
success: bool = True
|
||||
message: str
|
||||
project_path: str
|
||||
Reference in New Issue
Block a user