feat: 图片下载与数据目录本地化
- 新增 download_images.py: 批量下载消息图片到 downloads/images/ - 数据库移至 downloads/messages.db,SnifferStorage 默认使用项目目录 - 图片默认保存到 downloads/images/,支持 --out-dir 自定义 - .gitignore 排除 downloads/ 避免提交二进制文件 - 补充腾讯会议号过滤 prompt - 补充 Obsidian 文档 is_read frontmatter
This commit is contained in:
48
tests/test_card_images.py
Normal file
48
tests/test_card_images.py
Normal file
@ -0,0 +1,48 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
from snooper_card_images import enrich_card_images, extract_card_image_keys
|
||||
|
||||
|
||||
def test_extract_card_image_keys_deduplicates_json_and_binary_properties():
|
||||
key = b"img_v3_02ad_synthetic"
|
||||
data = {
|
||||
"imageKey": key.decode(),
|
||||
"richtext": {"elements": {"dictionary": {"1": {"property": key}}}},
|
||||
}
|
||||
|
||||
assert extract_card_image_keys(data) == [key.decode()]
|
||||
|
||||
|
||||
def test_enrich_card_images_uses_approved_vision_client(monkeypatch):
|
||||
key = b"img_v3_02ad_synthetic"
|
||||
client = SimpleNamespace(
|
||||
auth=SimpleNamespace(region=SimpleNamespace(file_host="https://example.com")),
|
||||
pull_history=lambda chat_id, positions, visible_only: [
|
||||
{
|
||||
"content_data": {
|
||||
"richtext": {
|
||||
"elements": {"dictionary": {"1": {"property": key}}}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
"snooper_card_images.download",
|
||||
lambda auth, url: (b"synthetic-image", "image/png"),
|
||||
)
|
||||
ai_client = SimpleNamespace(
|
||||
complete_with_image=lambda image, mime: "合成图片文字"
|
||||
)
|
||||
row = SimpleNamespace(
|
||||
msg_type=14,
|
||||
position=1,
|
||||
chat_id="chat-a",
|
||||
msg_id="message-a",
|
||||
content="[卡片] [图片]",
|
||||
)
|
||||
|
||||
stats = enrich_card_images(client, ai_client, [row])
|
||||
|
||||
assert stats == {"candidates": 1, "enriched": 1, "failed": 0}
|
||||
assert "合成图片文字" in row.content
|
||||
Reference in New Issue
Block a user