WechatOnCloud/bridge/woc_bridge/routes/screenshot.py
Kris 102b98adea refactor: 完成项目包结构重构与基础模块搭建
本次提交将woc-bridge项目重构为模块化包结构,按职责拆分多个子域:
1. 新增models层定义所有Pydantic数据模型与统一错误体系
2. 拆分db/ui/messaging/routes等业务域模块
3. 实现基础API路由:状态查询、截图、登录、媒体获取等
4. 重构tools脚本的模块导入路径
5. 补充版本号与能力清单定义
6. 完善全局配置与依赖管理

整体完成项目从单文件脚本到可维护的包结构迁移,为后续功能开发打下基础。
2026-07-08 23:25:58 +08:00

42 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from __future__ import annotations
import logging
from fastapi import APIRouter
from fastapi.responses import Response
from woc_bridge.config import _require_qr_capture
logger = logging.getLogger("woc-bridge")
router = APIRouter()
# ---------------------------------------------------------------------------
# 路由POST /api/screenshot
# ---------------------------------------------------------------------------
@router.post("/api/screenshot")
async def screenshot() -> Response:
"""截取完整屏幕并返回 PNG。
用于前端「截图」按钮 / 调试时观察微信实际界面状态(如确认 UI 操作是否
触发了正确的对话框)。截取整个 X 桌面DISPLAY 由 _state.config.display 指定)。
Returns:
ResponseContent-Type=image/pngbody 为 PNG 二进制
Raises:
BridgeError(WINDOW_NOT_FOUND): X 会话未就绪无法截图HTTP 503
其他异常由全局兜底处理器返回 BRIDGE_INTERNAL_ERROR
Notes:
- 截图由 qr_capture.capture_full_screenshot 完成,底层调
xdotool/getwindowgeometry + importImageMagick
- 与 /api/login/qr/start 区别本接口截全屏qr/start 截二维码区域
- 大屏幕截图可能 > 1MB调用方注意带宽
"""
qr_capture = _require_qr_capture()
png_bytes = await qr_capture.capture_full_screenshot()
logger.info("screenshot: → 截图成功 %d bytes", len(png_bytes))
return Response(content=png_bytes, media_type="image/png")