Peach: Local-first video metadata scraper and media manager.
fix(web): 关注图片墙瀑布流不再随图片加载重排
longmeidao91f2c5f0f3db
diff --git a/src/peach/web_follow.py b/src/peach/web_follow.pyindex f08c49da3..2a797278c 100644--- a/src/peach/web_follow.py+++ b/src/peach/web_follow.py@@ -702,6 +702,10 @@ def _media_projection(item) -> tuple[list[dict], list[dict]]:if kind == "video" else None,"thumb_url": thumb if thumb.startswith("https://") else None,"size": media.get("size"),+ # 固有宽高给瀑布流预留比例用:fanbox 的 imageMap 带原尺寸,没有的+ # 来源保持 None,前端按无尺寸那套占位。+ "width": _positive_dim(media.get("width")),+ "height": _positive_dim(media.get("height")),"resource_provider": str(media.get("resource_provider") or ""),"resource_group": str(media.get("resource_group") or "") or None,"resource_group_label": str(media.get("resource_group_label") or "") or None,@@ -710,6 +714,14 @@ def _media_projection(item) -> tuple[list[dict], list[dict]]:return visible, concealed+def _positive_dim(value) -> int | None:+ try:+ number = int(value)+ except (TypeError, ValueError):+ return None+ return number if number > 0 else None++def _media_items(item) -> list[dict]:"""给浏览器媒体序号和展示字段;真实上游 URL 仍只留在服务端 metadata。"""return _media_projection(item)[0]diff --git a/tests/test_follow_web.py b/tests/test_follow_web.pyindex a9b7d92bd..c9eca689a 100644--- a/tests/test_follow_web.py+++ b/tests/test_follow_web.py@@ -688,6 +688,24 @@ class FollowContractTests(unittest.TestCase):item = self._get()["groups"][0]["primary"]self.assertEqual([media_["index"] for media_ in item["media_items"]], [0])+ def test_media_projection_carries_intrinsic_dimensions(self):+ self._seed(candidates=(FollowCandidate(+ provider="fanbox", external_id="1", title="Post",+ url="https://lazyprocrast.fanbox.cc/posts/1",+ extra={"media_items": [+ {"id": "art", "media_kind": "image", "resource_provider": "fanbox",+ "url": "https://downloads.fanbox.cc/images/post/1/art.png",+ "thumb_url": "https://downloads.fanbox.cc/images/post/1/w/1200/art.jpeg",+ "width": 1920, "height": 1080},+ {"id": "mystery", "media_kind": "image", "resource_provider": "fanbox",+ "url": "https://downloads.fanbox.cc/images/post/1/m.png"},+ ]}),), provider="fanbox", ref="lazyprocrast")+ item = self._get()["groups"][0]["primary"]+ self.assertEqual(item["media_items"][0]["width"], 1920)+ self.assertEqual(item["media_items"][0]["height"], 1080)+ self.assertIsNone(item["media_items"][1]["width"])+ self.assertIsNone(item["media_items"][1]["height"])+def test_hidden_media_leaves_the_feed_and_the_card_thumb(self):chart = "https://downloads.fanbox.cc/images/post/1/w/1200/chart.jpeg"art = "https://downloads.fanbox.cc/images/post/1/w/1200/art.jpeg"diff --git a/web/app.js b/web/app.jsindex 254039149..e279ec2a5 100644--- a/web/app.js+++ b/web/app.js@@ -5920,8 +5920,14 @@ function followCard(group,authorSources=[]){const imageView=followMediaView==='images';const selectedMedia=imageView?(item.media_items||[]).find(media=>media.media_kind==='image'):null;const thumbUrl=selectedMedia?.thumb_url||item.thumb_url;+ /* width/height 属性让浏览器在图片落地前就按固有比例占位:瀑布流按卡片高度+ 分列,没有这两个属性时未加载的图高度是零,每一张加载完都把整墙的列重新+ 平衡一遍,卡片就在列间跳。没有可靠尺寸的来源不硬猜,走无尺寸占位那套。 */+ const dims=selectedMedia&&selectedMedia.thumb_url===thumbUrl+ &&selectedMedia.width>0&&selectedMedia.height>0+ ?` width="${selectedMedia.width}" height="${selectedMedia.height}"`:'';const thumb=thumbUrl- ? `<img src="${esc(thumbUrl)}" alt="" loading="lazy" referrerpolicy="no-referrer" data-drop="self">`+ ? `<img${dims} src="${esc(thumbUrl)}" alt="" loading="lazy" referrerpolicy="no-referrer" data-drop="self">`: `<span class="fnothumb">${sourceIcon(item.resource_provider||item.provider)}</span>`;const videos=followMediaView==='videos'?followVideoItems(group):[],embedded=item.media_items||[];const groupedOwner=followMediaView==='videos'?followGroupedMediaOwner(group):null;diff --git a/web/css/21-online.css b/web/css/21-online.cssindex 84e05ac12..295d67eed 100644--- a/web/css/21-online.css+++ b/web/css/21-online.css@@ -121,5 +121,8 @@[data-layout="masonry"]>.photocell{aspect-ratio:auto}[data-layout="masonry"]>.photocell img{height:auto;aspect-ratio:auto 1}[data-layout="masonry"] .followitem.imagecard .pic{aspect-ratio:1}-[data-layout="masonry"] .followitem.imagecard .pic:has(>img){aspect-ratio:auto}-[data-layout="masonry"] .followitem.imagecard .followvisual .pic>img{position:static;height:auto;aspect-ratio:auto 1}+/* 只有带 width/height 属性的图才放开高度按固有比例占位:瀑布流按卡片高度分列,+ 图没加载完高度未知时放手,每张加载完都会把整墙的列再平衡一遍,卡片在列间跳。+ 没有尺寸的图保持 1:1 占位框,图在框内 contain——列从首帧起就是稳定的。 */+[data-layout="masonry"] .followitem.imagecard .pic:has(>img[width][height]){aspect-ratio:auto}+[data-layout="masonry"] .followitem.imagecard .followvisual .pic>img[width][height]{position:static;height:auto;aspect-ratio:auto 1}