Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-03-11 17:53:30 +03:00
parent aba71341b9
commit 6ff8747411
8 changed files with 1373 additions and 129 deletions

View File

@@ -23,11 +23,53 @@ type ProductImageItem struct {
ContentURL string `json:"content_url"`
}
func tokenizeImageFileName(fileName string) []string {
up := strings.ToUpper(strings.TrimSpace(fileName))
if up == "" {
return nil
}
return strings.FieldsFunc(up, func(r rune) bool {
isUpper := r >= 'A' && r <= 'Z'
isDigit := r >= '0' && r <= '9'
if isUpper || isDigit || r == '_' {
return false
}
return true
})
}
func imageFileMatches(fileName, color, secondColor string) bool {
color = strings.ToUpper(strings.TrimSpace(color))
secondColor = strings.ToUpper(strings.TrimSpace(secondColor))
if color == "" && secondColor == "" {
return true
}
tokens := tokenizeImageFileName(fileName)
if len(tokens) == 0 {
return false
}
hasToken := func(target string) bool {
if target == "" {
return true
}
for _, t := range tokens {
if t == target {
return true
}
}
return false
}
return hasToken(color) && hasToken(secondColor)
}
//
// LIST PRODUCT IMAGES
//
// GET /api/product-images?code=...&color=...
// GET /api/product-images?code=...&color=...&yaka=...
func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
@@ -41,6 +83,10 @@ func GetProductImagesHandler(pg *sql.DB) http.HandlerFunc {
code := strings.TrimSpace(r.URL.Query().Get("code"))
color := strings.TrimSpace(r.URL.Query().Get("color"))
secondColor := strings.TrimSpace(r.URL.Query().Get("yaka"))
if secondColor == "" {
secondColor = strings.TrimSpace(r.URL.Query().Get("renk2"))
}
if code == "" {
@@ -67,18 +113,13 @@ JOIN mmitem i
WHERE b.typ = 'img'
AND b.src_table = 'mmitem'
AND UPPER(i.code) = UPPER($1)
AND (
$2 = ''
OR b.file_name ILIKE '%' || '-' || $2 || '-%'
OR b.file_name ILIKE '%' || '-' || $2 || '_%'
)
ORDER BY
COALESCE(b.sort_order,999999),
b.zlins_dttm DESC,
b.id DESC
`
rows, err := pg.Query(query, code, color)
rows, err := pg.Query(query, code)
if err != nil {
@@ -86,6 +127,7 @@ ORDER BY
"req_id", reqID,
"code", code,
"color", color,
"second_color", secondColor,
"err", err.Error(),
)
@@ -109,6 +151,9 @@ ORDER BY
); err != nil {
continue
}
if !imageFileMatches(it.FileName, color, secondColor) {
continue
}
it.ContentURL = fmt.Sprintf("/api/product-images/%d/content", it.ID)
@@ -119,6 +164,7 @@ ORDER BY
"req_id", reqID,
"code", code,
"color", color,
"second_color", secondColor,
"count", len(items),
)