| 930 | } |
| 931 | |
| 932 | func normalizeImageEditImages(rawImages []interface{}) []editImageInput { |
| 933 | out := make([]editImageInput, 0, len(rawImages)) |
| 934 | for _, raw := range rawImages { |
| 935 | switch v := raw.(type) { |
| 936 | case *multipart.FileHeader: |
| 937 | if v == nil { |
| 938 | continue |
| 939 | } |
| 940 | f, err := v.Open() |
| 941 | if err != nil { |
| 942 | continue |
| 943 | } |
| 944 | data, err := io.ReadAll(f) |
| 945 | f.Close() |
| 946 | if err != nil || len(data) == 0 { |
| 947 | continue |
| 948 | } |
| 949 | ct := v.Header.Get("Content-Type") |
| 950 | if ct == "" { |
| 951 | ct = "image/png" |
| 952 | } |
| 953 | name := v.Filename |
| 954 | if name == "" { |
| 955 | name = "image.png" |
| 956 | } |
| 957 | out = append(out, editImageInput{Data: data, Filename: name, ContentType: ct}) |
| 958 | case editImageInput: |
| 959 | if len(v.Data) > 0 { |
| 960 | out = append(out, v) |
| 961 | } |
| 962 | default: |
| 963 | // JSON 形态的 image 引用由 collectImageEditSourcesFromValue 处理,这里跳过 |
| 964 | } |
| 965 | } |
| 966 | return out |
| 967 | } |
| 968 | |
| 969 | func imageEditReadJSONImage(data []byte, filename, contentType string) (editImageInput, error) { |
| 970 | if len(data) == 0 { |