Spaces:
Paused
Paused
fix: restore required setup fields
Browse files- require CPA_URL and API_KEY again in setup checks while keeping proxy fields optional\n- default CPA_URL and auto-generate API_KEY when saving setup config\n- remove the host.docker.internal host-gateway mapping from default compose/docs
Files changed (8)
12345678services:autoteam:build: .extra_hosts:- "host.docker.internal:host-gateway"ports:- "8787:8787"volumes:123456services:autoteam:build: .ports:- "8787:8787"volumes:
13 unmodified lines14151617181920212213 unmodified lines| `CLOUDMAIL_EMAIL` | CloudMail 登录邮箱 | 是 || `CLOUDMAIL_PASSWORD` | CloudMail 登录密码 | 是 || `CLOUDMAIL_DOMAIN` | 临时邮箱域名(如 `@example.com`) | 是 || `CPA_URL` | CLIProxyAPI 地址 | 否(默认 `http://127.0.0.1:8317`) || `CPA_KEY` | CPA 管理密钥 | 是 || `API_KEY` | Web 面板 / API 鉴权密钥 | 否(首次启动自动生成) || `PLAYWRIGHT_PROXY_URL` | Playwright 浏览器代理 URL,如 `socks5://user:pass@host:port` | 否 || `PLAYWRIGHT_PROXY_BYPASS` | Playwright 代理绕过列表,如 `localhost,127.0.0.1` | 否 || `AUTO_CHECK_THRESHOLD` | 额度低于此百分比触发轮转 | 否(默认 `10`) |13 unmodified lines14151617181920212213 unmodified lines| `CLOUDMAIL_EMAIL` | CloudMail 登录邮箱 | 是 || `CLOUDMAIL_PASSWORD` | CloudMail 登录密码 | 是 || `CLOUDMAIL_DOMAIN` | 临时邮箱域名(如 `@example.com`) | 是 || `CPA_URL` | CLIProxyAPI 地址 | 是(留空使用默认 `http://127.0.0.1:8317`) || `CPA_KEY` | CPA 管理密钥 | 是 || `API_KEY` | Web 面板 / API 鉴权密钥 | 是(首次启动可自动生成) || `PLAYWRIGHT_PROXY_URL` | Playwright 浏览器代理 URL,如 `socks5://user:pass@host:port` | 否 || `PLAYWRIGHT_PROXY_BYPASS` | Playwright 代理绕过列表,如 `localhost,127.0.0.1` | 否 || `AUTO_CHECK_THRESHOLD` | 额度低于此百分比触发轮转 | 否(默认 `10`) |
117 unmodified lines118119120121122123124125126127128129117 unmodified lines直接打开 `http://your-server:8787`,会显示配置向导页面,在浏览器中填写。如果你需要让浏览器流量走宿主机 SOCKS5 代理,在 Linux Docker 下还需要给容器增加:```yamlextra_hosts:- "host.docker.internal:host-gateway"```然后在 `data/.env` 中加入:117 unmodified lines118119120121122123124117 unmodified lines直接打开 `http://your-server:8787`,会显示配置向导页面,在浏览器中填写。如果你需要让浏览器流量走宿主机 SOCKS5 代理,请先确认容器内可以解析并访问宿主机代理地址(例如 `host.docker.internal`,或你自己提供的宿主机网关别名)。然后在 `data/.env` 中加入:
169 unmodified lines170171172173174175176177178179180181169 unmodified lines### 容器里访问不到宿主机 SOCKS5 代理如果代理在宿主机上,比如 `host.docker.internal:1080`,Linux Docker 需要给容器补一条 host-gateway 映射:```yamlextra_hosts:- "host.docker.internal:host-gateway"```然后在 `data/.env` 中配置:169 unmodified lines170171172173174175176169 unmodified lines### 容器里访问不到宿主机 SOCKS5 代理如果代理在宿主机上,比如 `host.docker.internal:1080`,请先确认容器内可以解析并访问宿主机代理地址;不同 Docker / Podman 环境的宿主机别名配置方式可能不同。然后在 `data/.env` 中配置:
100 unmodified lines101102103104105106107108109100 unmodified lines"""保存配置到 .env 并验证连通性"""import secrets as _secretsfrom autoteam.setup_wizard import _write_envdata = config.model_dump()if not data.get("API_KEY"):data["API_KEY"] = _secrets.token_urlsafe(24)100 unmodified lines101102103104105106107108109110111112100 unmodified lines"""保存配置到 .env 并验证连通性"""import secrets as _secretsfrom autoteam.setup_wizard import REQUIRED_CONFIGS, _write_envdata = config.model_dump()defaults = {key: default for key, _prompt, default, _optional in REQUIRED_CONFIGS}if not data.get("CPA_URL"):data["CPA_URL"] = defaults.get("CPA_URL", "http://127.0.0.1:8317")if not data.get("API_KEY"):data["API_KEY"] = _secrets.token_urlsafe(24)
19 unmodified lines202122232425262728293019 unmodified lines("CLOUDMAIL_EMAIL", "CloudMail 登录邮箱", "", False),("CLOUDMAIL_PASSWORD", "CloudMail 登录密码", "", False),("CLOUDMAIL_DOMAIN", "CloudMail 邮箱域名(如 @example.com)", "", False),("CPA_URL", "CPA (CLIProxyAPI) 地址", "http://127.0.0.1:8317", True),("CPA_KEY", "CPA 管理密钥", "", False),("PLAYWRIGHT_PROXY_URL", "Playwright 浏览器代理 URL(可选,如 socks5://host:port)", "", True),("PLAYWRIGHT_PROXY_BYPASS", "Playwright 代理绕过列表(可选,如 localhost,127.0.0.1)", "", True),("API_KEY", "API 鉴权密钥(回车自动生成)", "", True),]19 unmodified lines202122232425262728293019 unmodified lines("CLOUDMAIL_EMAIL", "CloudMail 登录邮箱", "", False),("CLOUDMAIL_PASSWORD", "CloudMail 登录密码", "", False),("CLOUDMAIL_DOMAIN", "CloudMail 邮箱域名(如 @example.com)", "", False),("CPA_URL", "CPA (CLIProxyAPI) 地址", "http://127.0.0.1:8317", False),("CPA_KEY", "CPA 管理密钥", "", False),("PLAYWRIGHT_PROXY_URL", "Playwright 浏览器代理 URL(可选,如 socks5://host:port)", "", True),("PLAYWRIGHT_PROXY_BYPASS", "Playwright 代理绕过列表(可选,如 localhost,127.0.0.1)", "", True),("API_KEY", "API 鉴权密钥(回车自动生成)", "", False),]
66 unmodified lines67686966 unmodified linesassert sanitized["is_main_account"] is Trueassert sanitized["status"] == "active"66 unmodified lines67686970717273747576777879808182838485868788899091929394959697989910010110210310466 unmodified linesassert sanitized["is_main_account"] is Trueassert sanitized["status"] == "active"def test_post_setup_save_keeps_cpa_url_required_and_generates_api_key(monkeypatch):written = {}def fake_write_env(key, value):written[key] = valuemonkeypatch.setattr("autoteam.setup_wizard._write_env", fake_write_env)monkeypatch.setattr("autoteam.setup_wizard._verify_cloudmail", lambda: True)monkeypatch.setattr("autoteam.setup_wizard._verify_cpa", lambda: True)monkeypatch.setattr("secrets.token_urlsafe", lambda _n: "generated-token")monkeypatch.setattr("importlib.reload", lambda module: module)monkeypatch.setattr(api, "API_KEY", "")monkeypatch.delenv("CPA_URL", raising=False)monkeypatch.delenv("API_KEY", raising=False)result = api.post_setup_save(api.SetupConfig(CLOUDMAIL_BASE_URL="http://mail.example.com",CLOUDMAIL_EMAIL="admin@example.com",CLOUDMAIL_PASSWORD="secret",CLOUDMAIL_DOMAIN="@example.com",CPA_URL="",CPA_KEY="key-1",PLAYWRIGHT_PROXY_URL="",PLAYWRIGHT_PROXY_BYPASS="",API_KEY="",))assert written["CPA_URL"] == "http://127.0.0.1:8317"assert written["API_KEY"] == "generated-token"assert result["api_key"] == "generated-token"assert api.API_KEY == "generated-token"
80 unmodified lines818283848586878880 unmodified linesassert ok is Falseassert "[配置] 缺少必填项: CLOUDMAIL_BASE_URL" in caplog.textassert "[配置] 缺少必填项: CPA_KEY" in caplog.textassert "[配置] 缺少必填项: CPA_URL" not in caplog.textassert "[配置] 缺少必填项: PLAYWRIGHT_PROXY_URL" not in caplog.textassert "[配置] 缺少必填项: PLAYWRIGHT_PROXY_BYPASS" not in caplog.textassert "[配置] 缺少必填项: API_KEY" not in caplog.textassert "[配置] 请通过 Web 面板或编辑 .env 文件填入配置" in caplog.text80 unmodified lines818283848586878880 unmodified linesassert ok is Falseassert "[配置] 缺少必填项: CLOUDMAIL_BASE_URL" in caplog.textassert "[配置] 缺少必填项: CPA_KEY" in caplog.textassert "[配置] 缺少必填项: CPA_URL" in caplog.textassert "[配置] 缺少必填项: PLAYWRIGHT_PROXY_URL" not in caplog.textassert "[配置] 缺少必填项: PLAYWRIGHT_PROXY_BYPASS" not in caplog.textassert "[配置] 缺少必填项: API_KEY" in caplog.textassert "[配置] 请通过 Web 面板或编辑 .env 文件填入配置" in caplog.text
docker-compose.yml-2
docs/configuration.md+2-2
docs/getting-started.md+1-6
docs/troubleshooting.md+1-6
src/autoteam/api.py+4-1
src/autoteam/setup_wizard.py+2-2
tests/unit/test_api_status.py+35
tests/unit/test_setup_wizard.py+2-2