resolveEditImageSources 把 JSON images 数组 / image_url 字段解析为 []editImageInput。
(c *gin.Context, body map[string]interface{}, client httpclient.AuroraHttpClient)
| 1082 | |
| 1083 | // resolveEditImageSources 把 JSON images 数组 / image_url 字段解析为 []editImageInput。 |
| 1084 | func resolveEditImageSources(c *gin.Context, body map[string]interface{}, client httpclient.AuroraHttpClient) ([]editImageInput, error) { |
| 1085 | out := make([]editImageInput, 0, 2) |
| 1086 | appendValue := func(v interface{}) error { |
| 1087 | switch t := v.(type) { |
| 1088 | case string: |
| 1089 | item, ok, err := imageEditConvertURL(client, t) |
| 1090 | if err != nil { |
| 1091 | return err |
| 1092 | } |
| 1093 | if ok { |
| 1094 | out = append(out, item) |
| 1095 | } |
| 1096 | case map[string]interface{}: |
| 1097 | // 形如 {"image_url": "..."} 或 {"url": "..."} 或 {"b64_json": "..."} |
| 1098 | if urlVal, ok := t["image_url"]; ok { |
| 1099 | if s, ok := urlVal.(string); ok { |
| 1100 | item, _, err := imageEditConvertURL(client, s) |
| 1101 | if err != nil { |
| 1102 | return err |
| 1103 | } |
| 1104 | out = append(out, item) |
| 1105 | } |
| 1106 | } else if u, ok := t["url"]; ok { |
| 1107 | if s, ok := u.(string); ok { |
| 1108 | item, _, err := imageEditConvertURL(client, s) |
| 1109 | if err != nil { |
| 1110 | return err |
| 1111 | } |
| 1112 | out = append(out, item) |
| 1113 | } |
| 1114 | } else if b64, ok := t["b64_json"].(string); ok && b64 != "" { |
| 1115 | item, err := imageEditReadJSONImage([]byte(b64), "image.png", "image/png") |
| 1116 | if err != nil { |
| 1117 | return err |
| 1118 | } |
| 1119 | out = append(out, item) |
| 1120 | } else if b64, ok := t["base64"].(string); ok && b64 != "" { |
| 1121 | item, err := imageEditReadJSONImage([]byte(b64), "image.png", "image/png") |
| 1122 | if err != nil { |
| 1123 | return err |
| 1124 | } |
| 1125 | out = append(out, item) |
| 1126 | } |
| 1127 | } |
| 1128 | return nil |
| 1129 | } |
| 1130 | |
| 1131 | for _, key := range []string{"images", "image", "image_url"} { |
| 1132 | val, ok := body[key] |
| 1133 | if !ok || val == nil { |
| 1134 | continue |
| 1135 | } |
| 1136 | switch arr := val.(type) { |
| 1137 | case []interface{}: |
| 1138 | for _, item := range arr { |
| 1139 | if err := appendValue(item); err != nil { |
| 1140 | return nil, err |
| 1141 | } |
nothing calls this directly
no test coverage detected