2026-07-08 23:25:58 +08:00
|
|
|
|
"""woc-bridge FastAPI 薄入口(bridge 1.8.0 重构后)。
|
2026-07-07 19:04:13 +08:00
|
|
|
|
|
|
|
|
|
|
监听容器内 :8088,通过 xdotool/xclip 操作微信窗口、读取微信本地 DB,
|
|
|
|
|
|
提供收发消息等能力。
|
|
|
|
|
|
|
2026-07-08 23:25:58 +08:00
|
|
|
|
由 s6-rc 服务 `svc-woc-bridge` 常驻拉起(见 s6/woc-bridge/run),
|
2026-07-07 19:04:13 +08:00
|
|
|
|
启动前会等待微信窗口出现(最多 5 分钟),以确保 X 会话就绪。
|
|
|
|
|
|
|
2026-07-08 23:25:58 +08:00
|
|
|
|
本文件仅负责:
|
|
|
|
|
|
1. 解析命令行参数(--listen / --wechat-db / --display)
|
|
|
|
|
|
2. 构造 BridgeConfig 并调用 _init_state 初始化全局状态
|
|
|
|
|
|
3. 启动 uvicorn
|
2026-07-07 19:04:13 +08:00
|
|
|
|
|
2026-07-08 23:25:58 +08:00
|
|
|
|
所有业务逻辑(路由 / DB 协调 / UI 自动化 / 消息推送)均在 woc_bridge 包内。
|
2026-07-07 19:04:13 +08:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
import uvicorn
|
2026-07-07 20:17:06 +08:00
|
|
|
|
|
2026-07-08 23:25:58 +08:00
|
|
|
|
from woc_bridge.app import app, _init_state
|
|
|
|
|
|
from woc_bridge.config import BridgeConfig
|
2026-07-07 20:17:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
2026-07-07 19:04:13 +08:00
|
|
|
|
def _parse_args() -> argparse.Namespace:
|
|
|
|
|
|
"""解析命令行参数。"""
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="woc-bridge FastAPI 服务")
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--listen",
|
|
|
|
|
|
default="0.0.0.0:8088",
|
|
|
|
|
|
help="监听地址,格式 host:port,默认 0.0.0.0:8088",
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--wechat-db",
|
|
|
|
|
|
default="/config",
|
|
|
|
|
|
help="微信数据根目录,默认 /config(_find_db_path 会递归查找 message_0.db)",
|
|
|
|
|
|
)
|
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
|
"--display",
|
|
|
|
|
|
default=":1",
|
|
|
|
|
|
help="X server display,默认 :1",
|
|
|
|
|
|
)
|
|
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
args = _parse_args()
|
|
|
|
|
|
cfg = BridgeConfig.from_args_and_env(args)
|
|
|
|
|
|
_init_state(cfg)
|
|
|
|
|
|
host, _, port_str = cfg.listen.rpartition(":")
|
|
|
|
|
|
if not host:
|
|
|
|
|
|
host = "0.0.0.0"
|
|
|
|
|
|
port = int(port_str) if port_str else 8088
|
|
|
|
|
|
uvicorn.run(app, host=host, port=port)
|