chore: Remove obsolete scripts and enhance path configuration

- Deleted `check_md_files.py` and `fix_cursor_md_issue.py` as they are no longer needed.
- Added new functions in `path_config.py` for better path management, including actions log and run_cli paths.
- Updated various modules to utilize the new path configuration, ensuring consistency and maintainability across the project.
This commit is contained in:
Your Name committed 2025-12-28 20:55:34 +08:00
1 parent b9849b9f5a
commit bdf9312bc9
58 files changed
+2472 -854

No files matched your search

+43 -15
View File
@@ -11,9 +11,11 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from typing import Optional
from urllib.parse import parse_qs, urlparse
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CONFIG_PATH = os.path.join(BASE_DIR, "config", "config.json")
WEBUI_DIR = os.path.join(BASE_DIR, "webui")
import path_config
BASE_DIR = path_config.PROJECT_ROOT
CONFIG_PATH = path_config.get_config_path()
WEBUI_DIR = path_config.get_webui_dir()
# ANSI转义序列清理正则表达式
_ANSI_ESCAPE_RE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
@@ -85,7 +87,7 @@ class ProcRunner:
10000 # 0=不限制(可能占用大量内存),增加到10000避免日志被过早截断
)
self._log_file_enabled: bool = True
self._log_file_path: str = os.path.join(BASE_DIR, "logs", "unified.log")
self._log_file_path: str = path_config.get_log_file_path()
self._start_ts: Optional[float] = None
self._last_log_ts: Optional[float] = None
self._exit_code: Optional[int] = None
@@ -124,7 +126,7 @@ class ProcRunner:
path = str(cfg.get("log_unified_path") or "logs/unified.log")
if not os.path.isabs(path):
path = os.path.join(BASE_DIR, path)
path = os.path.join(path_config.PROJECT_ROOT, path)
self._log_file_path = path
try:
@@ -822,8 +824,13 @@ class ProcRunner:
return self._proc is not None and self._proc.poll() is None
def get_reservations(self) -> dict:
"""获取当前预约队列信息(来自子进程写入的 state/reservations.json)。"""
path = os.path.join(BASE_DIR, "state", "reservations.json")
"""获取当前预约队列信息(来自子进程写入的 douyin/core/state/reservations.json)。"""
try:
import path_config
path = path_config.get_reservations_path()
except Exception:
# 回退到旧路径(向后兼容)
path = path_config.get_reservations_path()
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -846,7 +853,7 @@ class ProcRunner:
def get_high_value_rooms(self) -> dict:
"""获取永久记录的高价值直播间列表(来自 state/high_value_rooms.json)。"""
path = os.path.join(BASE_DIR, "state", "high_value_rooms.json")
path = path_config.get_high_value_rooms_path()
try:
if os.path.exists(path):
with open(path, "r", encoding="utf-8") as f:
@@ -1080,9 +1087,16 @@ class ProcRunner:
if seconds <= 0:
seconds = 60
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"run_cli.py not found.\n"
f"Expected path: {run_cli_path}\n"
f"Please ensure run_cli.py is in the project root directory."
)
cmd = [
sys.executable,
os.path.join(BASE_DIR, "run_cli.py"),
run_cli_path,
"--test-yanghao-flow",
"--test-yanghao-flow-seconds",
str(seconds),
@@ -1097,9 +1111,16 @@ class ProcRunner:
raise RuntimeError("already running")
text = str(text or "").strip()
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"run_cli.py not found.\n"
f"Expected path: {run_cli_path}\n"
f"Please ensure run_cli.py is in the project root directory."
)
cmd = [
sys.executable,
os.path.join(BASE_DIR, "run_cli.py"),
run_cli_path,
"--test-comment",
]
if text:
@@ -1169,9 +1190,16 @@ class ProcRunner:
str(_pick("fansclub_fail_action", "") or "").strip().lower()
)
run_cli_path = path_config.get_run_cli_path()
if not os.path.exists(run_cli_path):
raise FileNotFoundError(
f"run_cli.py not found.\n"
f"Expected path: {run_cli_path}\n"
f"Please ensure run_cli.py is in the project root directory."
)
cmd = [
sys.executable,
os.path.join(BASE_DIR, "run_cli.py"),
run_cli_path,
"--y-pianyi",
str(y_pianyi),
"--wait-minutes",
@@ -1295,7 +1323,7 @@ class ProcRunner:
encoding="utf-8",
errors="replace",
env=env,
cwd=BASE_DIR,
cwd=path_config.PROJECT_ROOT,
bufsize=1, # 行缓冲模式,确保实时输出
)
@@ -1524,7 +1552,7 @@ class Handler(BaseHTTPRequestHandler):
path = (
RUNNER._log_file_path
if hasattr(RUNNER, "_log_file_path")
else os.path.join(BASE_DIR, "logs", "unified.log")
else path_config.get_log_file_path()
)
out_lines = []
try:
@@ -1555,7 +1583,7 @@ class Handler(BaseHTTPRequestHandler):
path = path_config.get_actions_log_path()
except Exception:
# 回退到旧路径(向后兼容)
path = os.path.join(BASE_DIR, "logs", "actions.log")
path = path_config.get_actions_log_path()
out_lines: list[str] = []
try:
if os.path.exists(path):
@@ -1580,7 +1608,7 @@ class Handler(BaseHTTPRequestHandler):
if not safe.startswith("pic/"):
self.send_error(HTTPStatus.FORBIDDEN)
return
full = os.path.join(BASE_DIR, safe)
full = os.path.join(path_config.PROJECT_ROOT, safe)
if not os.path.isfile(full):
self.send_error(HTTPStatus.NOT_FOUND)
return