mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-09-29 00:32:06 +08:00
添加uv支持 (#2119)
* bugfix:修复内存泄露和信号量饥饿问题 * 修复图片渲染按高度截断问题 * 优化图片渲染速度 * 权限检查去掉无效引用代码 * 添加uv支持 * 🚨 auto fix by pre-commit hooks * bugfix:修改gitignore换行 * bugfix:修复测试没有新生成uv.lock * 修复导入错误 * bugfix:移除重复调用 * 🚨 auto fix by pre-commit hooks * 清理残余poetry引用 * 更新uv安装方式 * 修复阿里云获取问题 * 增加资源下载提示 * 🚨 auto fix by pre-commit hooks * 修改资源下载为流式 * 🚨 auto fix by pre-commit hooks * 提高启动速度 * 移除bot.py支持 * 🚨 auto fix by pre-commit hooks * 优化win脚本逻辑 * 🚨 auto fix by pre-commit hooks * 清理残余无效逻辑 * 代码改进 * 🚨 auto fix by pre-commit hooks * 增加数据库迁移存在性检查 * 🚨 auto fix by pre-commit hooks * chore(test): 添加pytest超时控制和优雅关闭机制 - 在GitHub Actions工作流中添加作业级和步骤级超时限制,防止测试无限期挂起 - 添加pytest-timeout依赖并配置全局超时为120秒 - 在send_queue服务添加关闭钩子,确保worker任务正确取消 - 在priority_manager添加on_shutdown钩子,支持优先级生命周期的关闭阶段 * chore(lint): 禁用超长行的lint警告 * Modify restart logic for Windows platform * 🚨 auto fix by pre-commit hooks * bugfix:修复sys导入问题 * 清理无效结构 * bugfix:修复路径问题 * bugfix:修复shell语法传递给git导致资源获取失败问题 * 优化关闭显示 * bugfix:修复路径问题 * bugfix:增加路径安全 * bugfix:修复orm绕过问题 * 放宽numpy版本限制 * 修改重启方案 * bugfix:修复循环导入 * 优化逻辑 * Enhance disconnect function with error handling Added error handling for disconnect function and imported ConfigurationError. * Implement emergency restart mechanism Added emergency restart mechanism using atexit to ensure process restart even on severe exceptions during shutdown. * 🚨 auto fix by pre-commit hooks * 重启行为归一化 * 修复测试检测问题 * bugfix:修复测试侧类型报错问题 * 引入launcher机制 * 移除重启测试 * 收紧缓存调用路径 * 类型注解收敛 * 优化浏览器回收行为 * 优化浏览器渲染 * bugfix:解决重复关闭浏览器问题 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: ManyManyTomato <93612024+ATTomatoo@users.noreply.github.com> Co-authored-by: AkashiCoin <l1040186796@gmail.com>
This commit is contained in:
co-authored by
pre-commit-ci[bot]
ManyManyTomato
AkashiCoin
parent
74bf912d04
commit
8b16126e40
@@ -2,7 +2,6 @@ import contextlib
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
|
||||
from fastapi import Depends, HTTPException
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
@@ -42,32 +41,48 @@ def validate_path(path_str: str | None) -> tuple[Path | None, str | None]:
|
||||
if not path_str:
|
||||
return Path().resolve(), None
|
||||
|
||||
# 1. 移除任何可能的路径遍历尝试
|
||||
path_str = re.sub(r"[\\/]\.\.[\\/]", "", path_str)
|
||||
|
||||
# 2. 规范化路径并转换为绝对路径
|
||||
# 1. 规范化路径并转换为绝对路径(resolve() 会展开所有 .. 和符号链接)
|
||||
path = Path(path_str).resolve()
|
||||
|
||||
# 3. 获取项目根目录
|
||||
# 2. 获取项目根目录
|
||||
root_dir = Path().resolve()
|
||||
|
||||
# 4. 验证路径是否在项目根目录内
|
||||
# 3. 验证 resolve() 后的路径是否仍在项目根目录内(防路径穿越)
|
||||
try:
|
||||
if not path.is_relative_to(root_dir):
|
||||
return None, "访问路径超出允许范围"
|
||||
except ValueError:
|
||||
return None, "无效的路径格式"
|
||||
|
||||
# 5. 验证路径是否包含任何危险字符
|
||||
if any(c in str(path) for c in ["..", "~", "*", "?", ">", "<", "|", '"']):
|
||||
return None, "路径包含非法字符"
|
||||
|
||||
# 6. 验证路径长度是否合理
|
||||
# 4. 验证路径长度是否合理
|
||||
return (None, "路径长度超出限制") if len(str(path)) > 4096 else (path, None)
|
||||
except Exception as e:
|
||||
return None, f"路径验证失败: {e!s}"
|
||||
|
||||
|
||||
def validate_filename(name: str) -> str | None:
|
||||
"""验证文件名是否安全(不允许路径分隔符或路径穿越)
|
||||
|
||||
参数:
|
||||
name: 用户输入的文件名
|
||||
|
||||
返回:
|
||||
str | None: 错误信息,无错误则返回 None
|
||||
"""
|
||||
if not name or not name.strip():
|
||||
return "文件名不能为空"
|
||||
# 禁止任何路径分隔符,防止将文件名当路径使用
|
||||
if any(c in name for c in ("/", "\\", "\x00")):
|
||||
return "文件名包含非法路径分隔符"
|
||||
# 禁止 . 和 .. 作为文件名
|
||||
if name.strip(".") == "":
|
||||
return "文件名非法"
|
||||
# 禁止危险字符(Windows / Linux 通用)
|
||||
if any(c in name for c in ("<", ">", ":", '"', "|", "?", "*")):
|
||||
return "文件名包含非法字符"
|
||||
return None
|
||||
|
||||
|
||||
def get_user(uname: str) -> User | None:
|
||||
"""获取账号密码
|
||||
|
||||
@@ -141,7 +156,8 @@ def get_system_status() -> SystemStatus:
|
||||
"""获取系统信息等"""
|
||||
cpu = psutil.cpu_percent()
|
||||
memory = psutil.virtual_memory().percent
|
||||
disk = psutil.disk_usage("/").percent
|
||||
disk_root = Path().resolve().anchor # 跨平台:取当前工作目录所在盘的根
|
||||
disk = psutil.disk_usage(disk_root).percent
|
||||
return SystemStatus(
|
||||
cpu=cpu,
|
||||
memory=memory,
|
||||
@@ -155,7 +171,12 @@ def get_system_disk(
|
||||
full_path: str | None,
|
||||
) -> list[SystemFolderSize]:
|
||||
"""获取资源文件大小等"""
|
||||
base_path = Path(full_path) if full_path else Path()
|
||||
if full_path:
|
||||
base_path, err = validate_path(full_path)
|
||||
if err or not base_path:
|
||||
return []
|
||||
else:
|
||||
base_path = Path().resolve()
|
||||
other_size = 0
|
||||
data_list = []
|
||||
for file in os.listdir(base_path):
|
||||
|
||||
Reference in New Issue
Block a user