update
This commit is contained in:
@@ -146,6 +146,14 @@ func isInvalidAttributeKey(k string) bool {
|
||||
return !hasLetter
|
||||
}
|
||||
|
||||
// coreCharacteristicAttrKeys are always allowed on V1 process items even when
|
||||
// the company has no matching attributes row (common dims/brand/model).
|
||||
var coreCharacteristicAttrKeys = map[string]struct{}{
|
||||
"brand": {}, "product_model": {}, "warranty": {},
|
||||
"width": {}, "height": {}, "depth": {}, "weight": {},
|
||||
"energy_class": {}, "color": {}, "material": {},
|
||||
}
|
||||
|
||||
// SanitizeProductAttributes keeps characteristic attrs for API/storage and drops
|
||||
// core product fields that belong on the V1 item root (title, description, images, …).
|
||||
func SanitizeProductAttributes(attrs map[string]any) map[string]any {
|
||||
@@ -153,11 +161,48 @@ func SanitizeProductAttributes(attrs map[string]any) map[string]any {
|
||||
}
|
||||
|
||||
// SanitizeV1ProcessAttributes is the stricter poll projection: also drops eprel_*
|
||||
// keys (those are exposed on item.eprel).
|
||||
// keys (those are exposed on item.eprel). Without an allowlist, feed junk specs
|
||||
// (zavora, vzmetenje, …) can remain — prefer SanitizeV1ProcessAttributesAllowed.
|
||||
func SanitizeV1ProcessAttributes(attrs map[string]any) map[string]any {
|
||||
return sanitizeProductAttributes(attrs, true)
|
||||
}
|
||||
|
||||
// SanitizeV1ProcessAttributesAllowed sanitizes then keeps only core characteristic
|
||||
// keys plus company attribute_key values (canonicalized).
|
||||
func SanitizeV1ProcessAttributesAllowed(attrs map[string]any, allowed map[string]struct{}) map[string]any {
|
||||
return FilterAttributesByAllowed(sanitizeProductAttributes(attrs, true), allowed)
|
||||
}
|
||||
|
||||
// FilterAttributesByAllowed keeps coreCharacteristicAttrKeys plus keys present in
|
||||
// allowed (after canonicalizeAttrKey). When allowed is nil, returns attrs unchanged.
|
||||
func FilterAttributesByAllowed(attrs map[string]any, allowed map[string]struct{}) map[string]any {
|
||||
if len(attrs) == 0 {
|
||||
return map[string]any{}
|
||||
}
|
||||
if allowed == nil {
|
||||
return attrs
|
||||
}
|
||||
out := make(map[string]any, len(attrs))
|
||||
for k, v := range attrs {
|
||||
canon := canonicalizeAttrKey(k)
|
||||
if canon == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := coreCharacteristicAttrKeys[canon]; ok {
|
||||
out[canon] = v
|
||||
continue
|
||||
}
|
||||
if _, ok := allowed[canon]; ok {
|
||||
out[canon] = v
|
||||
continue
|
||||
}
|
||||
if _, ok := allowed[strings.ToLower(strings.TrimSpace(k))]; ok {
|
||||
out[canon] = v
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func sanitizeProductAttributes(attrs map[string]any, dropEPREL bool) map[string]any {
|
||||
if len(attrs) == 0 {
|
||||
return map[string]any{}
|
||||
|
||||
Reference in New Issue
Block a user