// Package ingest 爬虫侧入库客户端:把走秀元数据以 HMAC 签名 POST 到后台 // ingest 接口(:8092/admin/internal/ingest),替代原先直写 brand_runway 表。 // // 与后台 internal/pkg/hmac、internal/pkg/hashid 保持同算法,使爬虫模块完全解耦 // 于后端代码(不再 import 后端 internal 包),双方仅通过「签名 + JSON 载荷」契约通信。 package ingest import "strings" // 入库类型(与后台 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 用) 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 张细节图。 type RunwayLook struct { Main string `json:"main"` // 主图(look)原始 URL Details []string `json:"details"` // 细节图原始 URL 列表 } // ParseCollection 从 Vogue 标题推导 collection_type 与 season,供后台补 season_code。 // // "Fall 2024 Ready-to-Wear" -> ("rtw", "fall") // "Spring 2025 Menswear" -> ("menswear", "spring") // "Resort 2024" -> ("resort", "") // "Pre-Fall 2024" -> ("pre_fall", "") // "Couture Fall 2024" -> ("couture", "fall") func ParseCollection(title string) (collectionType, season string) { t := strings.ToLower(title) switch { case strings.Contains(t, "resort"): collectionType = "resort" case strings.Contains(t, "pre-fall"), strings.Contains(t, "pre fall"): collectionType = "pre_fall" case strings.Contains(t, "couture"): collectionType = "couture" case strings.Contains(t, "menswear"), strings.Contains(t, "men's"): collectionType = "menswear" case strings.Contains(t, "ready"): collectionType = "rtw" default: // 仅出现 spring/fall 而无明确品类词时,回落为 rtw(绝大多数季场秀) if strings.Contains(t, "spring") || strings.Contains(t, "fall") { collectionType = "rtw" } } switch { case strings.Contains(t, "spring"): season = "spring" case strings.Contains(t, "fall"): season = "fall" } return collectionType, season }