Files
spider/internal/ingest/payload.go
toom1996 463a57c497 feat: 跳过判定改为覆盖率(缺图能补,抓全才跳过)
此前只要某场秀已入库 >=10 张就整场跳过,当初只成功抓了十几张的场次
剩下的图永远补不上。

- payload 增加 expected_images(本场应有张数,后端据此算覆盖率)
- 跳过条件:images >= expected - 5;expected 未知时回落 10 张阈值
- 留 5 张余量:个别图在 Vogue 侧永久 404,要求一张不差会让这场秀
  永远判不完整、每次全量抓都重下一遍
2026-10-25 23:43:12 +08:00

53 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package ingest 爬虫侧入库客户端:把走秀元数据以 HMAC 签名 POST 到后台
// ingest 接口(:8092/admin/internal/ingest),替代原先直写 brand_runway 表。
//
// 与后台 internal/pkg/hmac、internal/pkg/hashid 保持同算法,使爬虫模块完全解耦
// 于后端代码(不再 import 后端 internal 包),双方仅通过「签名 + JSON 载荷」契约通信。
package ingest
// 入库类型(与后台 dto 保持一致)。
const (
KindRunway = "runway" // 走秀(默认,需 brand_uid)
KindStreet = "street" // 街拍(无品牌,需 city/title)
)
// RunwayIngest 与后台 dto.RunwayIngest 的 JSON 字段一一对应。
// 爬虫只传元数据 + 图片 URL 列表,图下载/OSS 由后台 worker 完成。
type RunwayIngest struct {
Kind string `json:"kind"` // runway | street,缺省 runway
BrandUID string `json:"brand_uid"` // 品牌 hashid(EncodeBrand 生成),runway 必填
TitleEn string `json:"title_en"` // 英文标题(优先;street 作为单标题)
TitleCn string `json:"title_cn"` // 中文标题(可空)
DescriptionEn string `json:"description_en"` // 英文描述(可空)
DescriptionCn string `json:"description_cn"` // 中文描述(可空)
Year uint16 `json:"year"` // 年份
Season string `json:"season"` // spring / fall
CollectionType string `json:"collection_type"` // rtw / menswear / couture / resort / pre_fall
City string `json:"city"` // 地区/城市(street 用)
PublishedAt uint32 `json:"published_at"` // Vogue 详情页 datePublished 的 Unix 时间戳(秒);0=未抽取。标题缺年份时用于矫正 year
// ExpectedImages 本场秀应有的图片总数(含细节图)。
// 后端用它做覆盖率判定:实际入库张数接近它才算抓全;否则下次重爬会来补。
ExpectedImages int `json:"expected_images,omitempty"`
Images []string `json:"images"` // 兼容旧 worker:铺平的主图 URL 列表
// Looks 结构化「主图 + 细节图」分组(Vogue 一个 gallery item = 1 主图 + N 细节图)。
// 结构化上报时优先用 Looks;为空时 worker 回退到 Images(全部视为主图)。
Looks []RunwayLook `json:"looks,omitempty"`
}
// RunwayLook 一场秀中的一个 look:1 张主图 + 0..N 张细节图。
//
// 两种上报形态(媒体机直传开关打开时用 key,否则用 URL):
// - 旧:Main/Details 给原始 URL,后端自己下载上传;
// - 新:MainKey/DetailKeys 给已上传的存储 key,后端跳过下载直接落库。
type RunwayLook struct {
Main string `json:"main"` // 主图(look)原始 URL
Details []string `json:"details"` // 细节图原始 URL 列表
MainKey string `json:"main_key,omitempty"` // 主图已上传 key(runway/<sha1>.jpg)
DetailKeys []string `json:"detail_keys,omitempty"` // 细节图已上传 key
MainSize int64 `json:"main_size,omitempty"` // 主图字节数
DetailSizes []int64 `json:"detail_sizes,omitempty"` // 细节图字节数(与 DetailKeys 对齐)
}