diff --git a/README.md b/README.md index 0304867..0fb13c7 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,11 @@ python -m maintain ### 3) 必填配置(配置编辑页) - `cliproxy_management_base`、`cliproxy_management_key`:巡检/清理必填。 -- `codex_stats_oauth_dir`:若 JSON 不在项目内 `accounts/oauth`,必须填真实目录(如 `~/.cli-proxy-api`)。 +- **CPA auths 固定目录**:部署时在仓库里改 `maintain/paths_config.py` 的 `CPA_AUTHS_DIR`(例如 NAS 挂载点 `/mnt/cpa_auths`)。新库默认会把 **`codex_stats_oauth_dir`** 与流水线 **`cpa_target_dir`** 设成该路径;**统计目录留空**时也会回落到该路径。已有 SQLite 里若仍是旧值,可在「配置编辑」里改一次或删掉对应 `settings` 行后重启。 - `cliproxy_sweeper_threshold` / `cliproxy_sweeper_run_mode`:控制 `/usage` 清理阈值与 delete/observe 模式。 +说明:注册仍先写到项目内 `accounts/oauth`;流水线「迁出」会把 JSON **移动**到 `cpa_target_dir`(即上述挂载目录)。若你希望统计/巡检直接扫 NAS,保持 `codex_stats_oauth_dir` 与挂载目录一致即可。 + ### 临时邮箱(mail.chatgpt.org.uk) - **`MAIL_API_KEY`** 或 **`EMAIL_API_KEY`**:调用 `https://mail.chatgpt.org.uk/api` 时放在请求头 **`X-API-Key`**(默认占位 `gpt-test`,生产请改成你自己的 key)。 diff --git a/maintain/app.py b/maintain/app.py index 37ebe4b..4e11105 100644 --- a/maintain/app.py +++ b/maintain/app.py @@ -1029,7 +1029,7 @@ def _before(): def main() -> None: db.init_db() - host = os.environ.get("CODEX_MAINTAIN_HOST", "127.0.0.1") + host = os.environ.get("CODEX_MAINTAIN_HOST", "0.0.0.0") port = int(os.environ.get("CODEX_MAINTAIN_PORT", "8765")) print( f"Codex 维护台 http://{host}:{port} " diff --git a/maintain/cpa_runner_core.py b/maintain/cpa_runner_core.py index d50b082..ab9276c 100644 --- a/maintain/cpa_runner_core.py +++ b/maintain/cpa_runner_core.py @@ -23,6 +23,8 @@ from urllib.parse import quote_plus import requests +from maintain.paths_config import CPA_AUTHS_DIR + REPO_ROOT = Path(__file__).resolve().parent.parent logger = logging.getLogger("cpa-runner") @@ -84,7 +86,7 @@ def runner_config_from_env() -> RunnerConfig: target_dir=Path( os.getenv( "TARGET_DIR", - str(REPO_ROOT / "export" / "cpa_auths"), + CPA_AUTHS_DIR, ) ).resolve(), python_bin=os.getenv("PYTHON_BIN", "python3"), @@ -424,9 +426,7 @@ def runner_config_from_db(get_setting: Callable[[str, str], str]) -> RunnerConfi oauth_dir=Path( g("pipeline_oauth_dir", str(REPO_ROOT / "accounts" / "oauth")) ).resolve(), - target_dir=Path( - g("cpa_target_dir", str(REPO_ROOT / "export" / "cpa_auths")) - ).resolve(), + target_dir=Path(g("cpa_target_dir", CPA_AUTHS_DIR)).resolve(), python_bin=g("pipeline_python_bin", "python3"), dingtalk_webhook=g("dingtalk_webhook", "").strip(), dingtalk_secret=g("dingtalk_secret", "").strip(), diff --git a/maintain/db.py b/maintain/db.py index 1e1f196..c6d807b 100644 --- a/maintain/db.py +++ b/maintain/db.py @@ -8,6 +8,8 @@ from datetime import datetime, timezone from pathlib import Path from typing import Any, Optional +from maintain.paths_config import CPA_AUTHS_DIR + ROOT = Path(__file__).resolve().parent.parent DB_PATH = ROOT / "maintain" / "data" / "maintain.db" ACCOUNTS_OAUTH = ROOT / "accounts" / "oauth" @@ -18,11 +20,12 @@ _lock = threading.Lock() def resolve_oauth_stats_dir() -> Path: """ 统计 / 巡检用的 codex JSON 目录。 - 留空 = 项目内 accounts/oauth;若注册成功后文件迁入 Cliproxy auth 目录,填该目录绝对路径。 + 配置留空时使用 maintain/paths_config.CPA_AUTHS_DIR(部署时写死挂载点)。 + 若需退回项目内目录,在「配置编辑」显式填项目 accounts/oauth 绝对路径。 """ raw = get_setting("codex_stats_oauth_dir", "").strip() if not raw: - return ACCOUNTS_OAUTH.resolve() + return Path(CPA_AUTHS_DIR).expanduser().resolve() return Path(raw).expanduser().resolve() @@ -92,7 +95,7 @@ def init_db() -> None: if cur.fetchone()[0] == 0: c.execute( "INSERT INTO cpa (name, code, target_count, api_base_url) VALUES (?,?,?,?)", - ("账号池", "default", 8000, ""), + ("账号池", "default", 500, ""), ) defaults = { "auto_inspect_enabled": "0", @@ -107,7 +110,7 @@ def init_db() -> None: "pipeline_interval_min": "10", "pipeline_run_script": str(ROOT / "run.py"), "pipeline_oauth_dir": str(ROOT / "accounts" / "oauth"), - "cpa_target_dir": str(ROOT / "export" / "cpa_auths"), + "cpa_target_dir": CPA_AUTHS_DIR, "pipeline_python_bin": "python3", "run_subprocess_timeout_sec": "480", "cpa_exit_on_empty": "0", @@ -120,8 +123,8 @@ def init_db() -> None: "cliproxy_sweeper_threshold": "3", "cliproxy_sweeper_run_mode": "delete", "cliproxy_sweeper_allow_name_fallback": "1", - # 成功后 JSON 若在 Cliproxy auth 目录,填绝对路径;留空则用项目 accounts/oauth - "codex_stats_oauth_dir": "", + # 与 paths_config.CPA_AUTHS_DIR 一致;可在 Web 里改 + "codex_stats_oauth_dir": CPA_AUTHS_DIR, "inspect_probe_valid_json": "", "pipeline_state_file": str(ROOT / "maintain" / "data" / "pipeline_state.json"), "pipeline_log_file": str(ROOT / "maintain" / "data" / "pipeline.log"), diff --git a/maintain/paths_config.py b/maintain/paths_config.py new file mode 100644 index 0000000..9da9871 --- /dev/null +++ b/maintain/paths_config.py @@ -0,0 +1,9 @@ +"""部署侧固定路径:改这一处即可。 + +NAS / SMB 请先挂载到本机目录(例如 /mnt/cpa_auths),此处填挂载后的绝对路径。 +勿填 smb:// URL。 +""" +from __future__ import annotations + +# 例如: sudo mount -t cifs //192.168.1.10/share/auths /mnt/nas-share/cpaauths +CPA_AUTHS_DIR = "/mnt/nas-share/cpaauths"