WechatOnCloud/bridge/woc_bridge/routes/screenshot.py
Kris c45282f094 feat: 新增好友自动通过、UI自动化能力与多分辨率适配
- 新增登录状态守卫后台任务
- 新增好友申请自动通过规则引擎
- 新增多分辨率UI配置与模板资源
- 新增消息拉取复合游标支持
- 优化发送队列与UI自动化逻辑
- 新增批量发送日志与错误处理
- 优化Docker镜像构建与ptrace初始化
- 新增联系人名称缓存预热
2026-07-17 18:10:31 +08:00

51 lines
1.8 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
from woc_bridge.models import BridgeError
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调用方注意带宽
"""
logger.info("screenshot: 收到请求")
qr_capture = _require_qr_capture()
try:
png_bytes = await qr_capture.capture_full_screenshot()
except BridgeError as e:
logger.warning("screenshot: 失败 %s: %s", e.code, e.message)
raise
except Exception as e:
logger.warning("screenshot: 失败 %s: %s", type(e).__name__, e)
raise
logger.info("screenshot: ✓ 截图成功 %d bytes", len(png_bytes))
return Response(content=png_bytes, media_type="image/png")