本次提交将woc-bridge项目重构为模块化包结构,按职责拆分多个子域: 1. 新增models层定义所有Pydantic数据模型与统一错误体系 2. 拆分db/ui/messaging/routes等业务域模块 3. 实现基础API路由:状态查询、截图、登录、媒体获取等 4. 重构tools脚本的模块导入路径 5. 补充版本号与能力清单定义 6. 完善全局配置与依赖管理 整体完成项目从单文件脚本到可维护的包结构迁移,为后续功能开发打下基础。
53 lines
2.3 KiB
Python
53 lines
2.3 KiB
Python
"""消息域模型:单条消息 / 消息拉取响应。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 消息接口(GET /api/messages/since)
|
||
# ---------------------------------------------------------------------------
|
||
class Message(BaseModel):
|
||
"""单条微信消息。"""
|
||
|
||
msg_id: str = Field(description="消息 ID")
|
||
talker: str = Field(description="会话对方 wxid(群消息为 chatroom id)")
|
||
sender: str = Field(default="", description="实际发送者 wxid(群消息中为成员 wxid)")
|
||
is_sender: bool = Field(default=False, description="是否为本机发送")
|
||
type: int = Field(description="微信原始消息类型")
|
||
render_type: str = Field(description="渲染类型:text/image/voice/video/file/system")
|
||
content: str = Field(default="", description="消息内容文本")
|
||
create_time: int = Field(description="消息时间戳(Unix 秒)")
|
||
session_type: str = Field(description="会话类型:p2p / group")
|
||
|
||
|
||
class MessagesResponse(BaseModel):
|
||
"""消息拉取响应。"""
|
||
|
||
messages: list[Message] = Field(default_factory=list)
|
||
next_cursor: int = Field(description="下次拉取应使用的 cursor")
|
||
has_more: bool = Field(default=False, description="是否可能还有更多消息")
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 按会话拉取(GET /api/messages/by_session)
|
||
# ---------------------------------------------------------------------------
|
||
class MessagesBySessionResponse(BaseModel):
|
||
"""按会话拉取历史消息响应。"""
|
||
|
||
messages: list[Message] = Field(default_factory=list)
|
||
next_cursor: int = Field(description="下次拉取应使用的 cursor")
|
||
has_more: bool = Field(default=False, description="是否可能还有更多消息")
|
||
talker: str = Field(description="本次查询的会话对方 wxid")
|
||
|
||
|
||
# ---------------------------------------------------------------------------
|
||
# 消息搜索(GET /api/messages/search)
|
||
# ---------------------------------------------------------------------------
|
||
class MessageSearchResponse(BaseModel):
|
||
"""消息搜索响应。"""
|
||
|
||
messages: list[Message] = Field(default_factory=list)
|
||
total: int = Field(default=0, description="命中总数(可能大于返回条数)")
|