All checks were successful
Build and Deploy Front / deploy (push) Successful in 6m37s
将站点/API 默认值收敛到配置,避免再次全局改域名;同步 H5/PC 支付充值与助手浮层交互调整。 Co-authored-by: Cursor <cursoragent@cursor.com>
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
"""本地配置持久化。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import json
|
||
from dataclasses import asdict, dataclass
|
||
from pathlib import Path
|
||
|
||
|
||
@dataclass
|
||
class AgentSettings:
|
||
# 默认对齐前端 deployTargets 测试 Admin;可用本地配置覆盖
|
||
oms_url: str = "https://api.test.bcdship.com/admin"
|
||
token: str = ""
|
||
device_name: str = ""
|
||
bridge_port: int = 9333
|
||
web_origin: str = "http://localhost:5173"
|
||
|
||
@staticmethod
|
||
def config_path() -> Path:
|
||
base = Path.home() / ".oms-xhs-agent"
|
||
base.mkdir(parents=True, exist_ok=True)
|
||
return base / "settings.json"
|
||
|
||
@classmethod
|
||
def load(cls) -> AgentSettings:
|
||
path = cls.config_path()
|
||
if not path.is_file():
|
||
return cls()
|
||
try:
|
||
raw = json.loads(path.read_text(encoding="utf-8"))
|
||
if not isinstance(raw, dict):
|
||
return cls()
|
||
return cls(
|
||
oms_url=str(raw.get("oms_url") or cls().oms_url),
|
||
token=str(raw.get("token") or ""),
|
||
device_name=str(raw.get("device_name") or ""),
|
||
bridge_port=int(raw.get("bridge_port") or 9333),
|
||
web_origin=str(raw.get("web_origin") or cls().web_origin),
|
||
)
|
||
except (json.JSONDecodeError, OSError, ValueError):
|
||
return cls()
|
||
|
||
def save(self) -> None:
|
||
path = self.config_path()
|
||
path.write_text(
|
||
json.dumps(asdict(self), ensure_ascii=False, indent=2),
|
||
encoding="utf-8",
|
||
)
|