本次提交将woc-bridge项目重构为模块化包结构,按职责拆分多个子域: 1. 新增models层定义所有Pydantic数据模型与统一错误体系 2. 拆分db/ui/messaging/routes等业务域模块 3. 实现基础API路由:状态查询、截图、登录、媒体获取等 4. 重构tools脚本的模块导入路径 5. 补充版本号与能力清单定义 6. 完善全局配置与依赖管理 整体完成项目从单文件脚本到可维护的包结构迁移,为后续功能开发打下基础。
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
"""woc-bridge FastAPI 薄入口(bridge 1.8.0 重构后)。
|
||
|
||
监听容器内 :8088,通过 xdotool/xclip 操作微信窗口、读取微信本地 DB,
|
||
提供收发消息等能力。
|
||
|
||
由 s6-rc 服务 `svc-woc-bridge` 常驻拉起(见 s6/woc-bridge/run),
|
||
启动前会等待微信窗口出现(最多 5 分钟),以确保 X 会话就绪。
|
||
|
||
本文件仅负责:
|
||
1. 解析命令行参数(--listen / --wechat-db / --display)
|
||
2. 构造 BridgeConfig 并调用 _init_state 初始化全局状态
|
||
3. 启动 uvicorn
|
||
|
||
所有业务逻辑(路由 / DB 协调 / UI 自动化 / 消息推送)均在 woc_bridge 包内。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
import argparse
|
||
|
||
import uvicorn
|
||
|
||
from woc_bridge.app import app, _init_state
|
||
from woc_bridge.config import BridgeConfig
|
||
|
||
|
||
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)
|