update sql表名
This commit is contained in:
parent
f88aca74f2
commit
51f988e535
@ -164,36 +164,60 @@ async def list_files(path: str = "", recursive: bool = False):
|
|||||||
async def upload_file(file: UploadFile = File(...), path: str = Form("")):
|
async def upload_file(file: UploadFile = File(...), path: str = Form("")):
|
||||||
"""
|
"""
|
||||||
上传文件
|
上传文件
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file: 上传的文件
|
file: 上传的文件
|
||||||
path: 目标路径(相对于支持目录)
|
path: 目标路径(相对于支持目录),如果不存在会自动创建
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
target_path = resolve_path(path) if path else resolve_path("projects")
|
# 如果没有指定路径,默认使用 projects 目录
|
||||||
if not target_path.exists() or not target_path.is_dir():
|
if not path:
|
||||||
target_path = resolve_path("projects")
|
target_path = resolve_path("projects")
|
||||||
|
else:
|
||||||
|
# 验证路径格式是否合法(必须以支持的目录开头)
|
||||||
|
path_parts = Path(path).parts
|
||||||
|
if not path_parts or path_parts[0] not in SUPPORTED_DIRECTORIES:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=400,
|
||||||
|
detail=f"路径必须以以下目录之一开头: {', '.join(SUPPORTED_DIRECTORIES)}"
|
||||||
|
)
|
||||||
|
# 直接构建路径,不检查是否存在(稍后会创建)
|
||||||
|
target_path = PROJECTS_DIR / path
|
||||||
|
|
||||||
|
# 如果目标路径已存在且是文件,则使用其父目录
|
||||||
|
if target_path.exists() and target_path.is_file():
|
||||||
|
target_path = target_path.parent
|
||||||
|
|
||||||
|
# 创建目标目录(包括所有不存在的父目录)
|
||||||
target_path.mkdir(parents=True, exist_ok=True)
|
target_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
file_path = target_path / file.filename
|
file_path = target_path / file.filename
|
||||||
|
|
||||||
# 如果文件已存在,检查是否覆盖
|
# 如果文件已存在,检查是否覆盖
|
||||||
if file_path.exists():
|
if file_path.exists():
|
||||||
# 可以添加版本控制或重命名逻辑
|
# 可以添加版本控制或重命名逻辑
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with open(file_path, "wb") as buffer:
|
with open(file_path, "wb") as buffer:
|
||||||
content = await file.read()
|
content = await file.read()
|
||||||
buffer.write(content)
|
buffer.write(content)
|
||||||
|
|
||||||
|
# 计算返回的相对路径
|
||||||
|
try:
|
||||||
|
relative_path = file_path.relative_to(PROJECTS_DIR)
|
||||||
|
except ValueError:
|
||||||
|
relative_path = file_path
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
"message": "文件上传成功",
|
"message": "文件上传成功",
|
||||||
"filename": file.filename,
|
"filename": file.filename,
|
||||||
"path": str(Path(path) / file.filename),
|
"path": str(relative_path),
|
||||||
"size": len(content)
|
"size": len(content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise HTTPException(status_code=500, detail=f"文件上传失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"文件上传失败: {str(e)}")
|
||||||
|
|
||||||
|
|||||||
@ -465,7 +465,7 @@ async def fetch_bot_config_from_db(bot_user_id: str) -> Dict[str, Any]:
|
|||||||
async with conn.cursor() as cursor:
|
async with conn.cursor() as cursor:
|
||||||
# 首先根据 bot_user_id 查找 bot 的 UUID
|
# 首先根据 bot_user_id 查找 bot 的 UUID
|
||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"SELECT id, name FROM bots WHERE bot_id = %s",
|
"SELECT id, name FROM agent_bots WHERE bot_id = %s",
|
||||||
(bot_user_id,)
|
(bot_user_id,)
|
||||||
)
|
)
|
||||||
bot_row = await cursor.fetchone()
|
bot_row = await cursor.fetchone()
|
||||||
@ -484,7 +484,7 @@ async def fetch_bot_config_from_db(bot_user_id: str) -> Dict[str, Any]:
|
|||||||
SELECT model_id,
|
SELECT model_id,
|
||||||
language, robot_type, dataset_ids, system_prompt, user_identifier,
|
language, robot_type, dataset_ids, system_prompt, user_identifier,
|
||||||
enable_memori, tool_response, skills
|
enable_memori, tool_response, skills
|
||||||
FROM bot_settings WHERE bot_id = %s
|
FROM agent_bot_settings WHERE bot_id = %s
|
||||||
""",
|
""",
|
||||||
(bot_uuid,)
|
(bot_uuid,)
|
||||||
)
|
)
|
||||||
@ -521,7 +521,7 @@ async def fetch_bot_config_from_db(bot_user_id: str) -> Dict[str, Any]:
|
|||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"""
|
"""
|
||||||
SELECT model, server, api_key
|
SELECT model, server, api_key
|
||||||
FROM models WHERE id = %s
|
FROM agent_models WHERE id = %s
|
||||||
""",
|
""",
|
||||||
(model_id,)
|
(model_id,)
|
||||||
)
|
)
|
||||||
@ -570,7 +570,7 @@ async def fetch_bot_config_from_db(bot_user_id: str) -> Dict[str, Any]:
|
|||||||
await cursor.execute(
|
await cursor.execute(
|
||||||
"""
|
"""
|
||||||
SELECT name, type, config, enabled
|
SELECT name, type, config, enabled
|
||||||
FROM mcp_servers WHERE bot_id = %s AND enabled = true
|
FROM agent_mcp_servers WHERE bot_id = %s AND enabled = true
|
||||||
""",
|
""",
|
||||||
(bot_uuid,)
|
(bot_uuid,)
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user