feat(meituan-coupon): 采集记录头图大小/类型 + 读取侧缩放口子 + 回填脚本 (#71)
Reviewed-on: #71 Co-authored-by: chenshuobo <chenshuobo@wonderable.ai> Co-committed-by: chenshuobo <chenshuobo@wonderable.ai>
This commit was merged in pull request #71.
This commit is contained in:
@@ -55,6 +55,10 @@ class MeituanCoupon(Base):
|
||||
sell_price_cents: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
original_price_cents: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
||||
head_url: Mapped[str | None] = mapped_column(String(512), nullable=True)
|
||||
# 头图字节大小 / MIME 类型:采集时 HEAD head_url 得到(Content-Length / Content-Type)。
|
||||
# 读取侧已统一压缩(不再按大小判定),这两列保留用于分析/监控(GIF 占比、体积分布等)。
|
||||
image_size: Mapped[int | None] = mapped_column(Integer, nullable=True) # 字节
|
||||
image_type: Mapped[str | None] = mapped_column(String(32), nullable=True) # 如 image/jpeg
|
||||
|
||||
# ===== 销量(美团只给粗档位:热销1w+;num=排序用的下界数值,如 1w+ → 10000) =====
|
||||
sale_volume: Mapped[str | None] = mapped_column(String(32), nullable=True)
|
||||
|
||||
+16
-1
@@ -13,6 +13,21 @@ from pydantic import BaseModel, Field
|
||||
FeedStatus = Literal["ok", "empty", "degraded"]
|
||||
|
||||
|
||||
# ───────────────── 头图传输优化(统一缩放 + 转 WebP) ─────────────────
|
||||
# 美团图片 CDN 支持在 URL 后拼 @<w>w_<h>h_1e_1c[.webp] 让服务端缩放/转码。feed 卡片只占
|
||||
# 124dp(≈372px@3x),而库里 head_url 是原图(实测中位 137KB、长尾到 17MB、GIF 均 4.8MB),
|
||||
# 是首页 feed 图片加载偏慢的来源。按产品要求,头图**统一**缩到 124dp + 转 WebP 再下发
|
||||
# (全部压缩、不设大小阈值),由美团 CDN 服务端缩放/转码,实测省 76–99% 体积。
|
||||
FEED_THUMB_PARAM = "@375w_375h_1e_1c.webp" # 124dp@3x 缩略 + 转 WebP
|
||||
|
||||
|
||||
def feed_image_url(head_url: str) -> str:
|
||||
"""统一给头图 URL 拼缩放参数(缩到 124dp + 转 WebP),让美团 CDN 出小图;空 URL 原样返回。"""
|
||||
if not head_url:
|
||||
return head_url
|
||||
return head_url.split("@")[0] + FEED_THUMB_PARAM
|
||||
|
||||
|
||||
# ───────────────── 券卡片(归一化后给客户端) ─────────────────
|
||||
|
||||
class CouponCard(BaseModel):
|
||||
@@ -94,7 +109,7 @@ class CouponCard(BaseModel):
|
||||
platform=platform,
|
||||
biz_line=biz_line,
|
||||
name=cpd.get("name") or "",
|
||||
head_image_url=head_url,
|
||||
head_image_url=feed_image_url(head_url),
|
||||
brand_name=brand.get("brandName"),
|
||||
brand_logo_url=brand.get("brandLogoUrl"),
|
||||
sell_price=sell,
|
||||
|
||||
Reference in New Issue
Block a user