topfans/backend/gateway/service/modelscope_client.go
2026-06-03 22:19:22 +08:00

55 lines
1.3 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 service
// pickModelScopeImageURL 从各类抠图 API 返回体中递归提取图片 URL通用工具函数
func pickModelScopeImageURL(v interface{}) string {
switch t := v.(type) {
case string:
if isHTTPURL(t) {
return t
}
case map[string]interface{}:
for _, key := range []string{"url", "image_url", "output_url", "result_url", "cutout_url"} {
if u, ok := t[key].(string); ok && isHTTPURL(u) {
return u
}
}
if images, ok := t["images"].([]interface{}); ok && len(images) > 0 {
if item, ok := images[0].(map[string]interface{}); ok {
if u := pickModelScopeImageURL(item); u != "" {
return u
}
}
if u, ok := images[0].(string); ok && isHTTPURL(u) {
return u
}
}
if output, ok := t["output"].(map[string]interface{}); ok {
if u := pickModelScopeImageURL(output); u != "" {
return u
}
}
if result, ok := t["result"].(map[string]interface{}); ok {
if u := pickModelScopeImageURL(result); u != "" {
return u
}
}
if data, ok := t["data"].(map[string]interface{}); ok {
if u := pickModelScopeImageURL(data); u != "" {
return u
}
}
for _, val := range t {
if u := pickModelScopeImageURL(val); u != "" {
return u
}
}
case []interface{}:
for _, item := range t {
if u := pickModelScopeImageURL(item); u != "" {
return u
}
}
}
return ""
}