Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(web): 身份引用只在有图时带 image_version

longmeidao2fee751e006a
diff --git a/src/peach/web_catalog.py b/src/peach/web_catalog.py
index ce868a67c..007af0196 100644
--- a/src/peach/web_catalog.py
+++ b/src/peach/web_catalog.py
@@ -440,9 +440,9 @@ def entity_ref(contract: WebContract, kind: str, entity_id, name: str) -> dict:
不去问盘。
"""
has_image = contract.has_entity_image(kind, entity_id)
- ref = {"id": entity_id, "name": name, "has_image": has_image,
- "image_version": contract.entity_image_version(kind, entity_id)}
+ ref = {"id": entity_id, "name": name, "has_image": has_image}
if has_image:
+ ref["image_version"] = contract.entity_image_version(kind, entity_id)
ref["avatar_focus"] = contract.avatar_focus(kind, entity_id)
return ref
diff --git a/src/peach/web_feeds.py b/src/peach/web_feeds.py
index 71332384c..77d49ecbc 100644
--- a/src/peach/web_feeds.py
+++ b/src/peach/web_feeds.py
@@ -238,7 +238,7 @@ def q_feeds(contract, args) -> dict:
for row in rows:
ref = web_catalog.entity_ref(contract, "performer", row["entity_id"], row["name"])
row["has_image"] = ref["has_image"]
- row["image_version"] = ref["image_version"]
+ row["image_version"] = ref.get("image_version", "")
row["avatar_focus"] = ref.get("avatar_focus")
pending = connection.execute(
"SELECT count(*) FROM feed_discovery d WHERE d.ignored_at IS NULL"
diff --git a/tests/test_rm_web.py b/tests/test_rm_web.py
index 63c88fef4..ffb8f25cf 100644
--- a/tests/test_rm_web.py
+++ b/tests/test_rm_web.py
@@ -96,7 +96,9 @@ class WebDataTests(unittest.TestCase):
(self.avatars / f"{entity_image_key('creator', 12)}.img").write_bytes(b"image")
row = rm_web.q_items(self.contract, {"limit": "10"})["items"][0]
ref = {"id": 12, "name": "Canonical Creator", "has_image": True,
+ "image_version": self.contract.entity_image_version("creator", 12),
"avatar_focus": None}
+ self.assertTrue(ref["image_version"])
self.assertEqual(row["creator_entity"], ref)
self.assertEqual(row["creator"], ref["name"])
self.assertEqual(rm_web.q_item(self.contract, row["id"])["entity_refs"]["creator"][0], ref)
diff --git a/tests/test_web_ui.py b/tests/test_web_ui.py
index d9a381e30..e68278288 100644
--- a/tests/test_web_ui.py
+++ b/tests/test_web_ui.py
@@ -1613,7 +1613,7 @@ class WebUiSourceTests(unittest.TestCase):
self.assertPageContains("hasImage:!!(ref&&ref.has_image)")
# 索引页(`/api/index`):实体图看 has_image、代表作头像看 has_avatar,kind
# 跟着这一页的身份走——创作者的图写成 `performer-<id>.img` 是读不到的。
- self.assertPageContains("ref?{id:ref,has_image:x.has_image}:null,")
+ self.assertPageContains("ref?{id:ref,has_image:x.has_image,image_version:x.image_version}:null,")
self.assertPageContains(
"x.has_avatar&&!company?x.rep:null,kind,x.mark,x.has_logo?x.k:'',")
# 口味榜(`/api/taste`)归 React 档,判据仍是同一对:引用给 `avatarInner()`,
@@ -4617,7 +4617,7 @@ class WebUiSourceTests(unittest.TestCase):
# 圆框越小越需要取景:一张 3762×2535 的封面塞进 44px 的圆里,几何居中给出的是
# 封面正中那块版式,脸在不在里面全看运气。按人脸框放大由 e2e 设计用例量。
self.assertPageContains(
- "{id:x.id,hasImage:x.has_image,rep:x.has_avatar?x.rep:null,")
+ "{id:x.id,hasImage:x.has_image,version:x.image_version,rep:x.has_avatar?x.rep:null,")
def test_a_company_cell_is_square_because_it_holds_a_mark_not_a_face(self):
"""3:4 是给脸留的形状,方标铺进去左右各被 `object-fit:cover` 裁掉四分之一。