Skip to content

Commit 10e615b

Browse files
committed
relocate all model functionality to declcfg and eliminate model package
Signed-off-by: grokspawn <jordan@nimblewidget.com>
1 parent 9933bd6 commit 10e615b

28 files changed

Lines changed: 970 additions & 4114 deletions

alpha/action/init.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66

77
"github.com/h2non/filetype"
8+
"github.com/h2non/go-is-svg"
89

910
"github.com/operator-framework/operator-registry/alpha/declcfg"
1011
)
@@ -36,16 +37,31 @@ func (i Init) Run() (*declcfg.Package, error) {
3637
if err != nil {
3738
return nil, fmt.Errorf("read icon: %v", err)
3839
}
40+
41+
// Try filetype detection first
3942
iconType, err := filetype.Match(iconData)
4043
if err != nil {
4144
return nil, fmt.Errorf("detect icon mediatype: %v", err)
4245
}
43-
if iconType.MIME.Type != "image" {
44-
return nil, fmt.Errorf("detected invalid type %q: not an image", iconType.MIME.Value)
46+
47+
var mediaType string
48+
// If filetype didn't detect it, check if it's SVG
49+
if iconType.MIME.Value == "" {
50+
if issvg.Is(iconData) {
51+
mediaType = "image/svg+xml"
52+
} else {
53+
return nil, fmt.Errorf("detected invalid type %q: not an image", iconType.MIME.Value)
54+
}
55+
} else {
56+
if iconType.MIME.Type != "image" {
57+
return nil, fmt.Errorf("detected invalid type %q: not an image", iconType.MIME.Value)
58+
}
59+
mediaType = iconType.MIME.Value
4560
}
61+
4662
pkg.Icon = &declcfg.Icon{
4763
Data: iconData,
48-
MediaType: iconType.MIME.Value,
64+
MediaType: mediaType,
4965
}
5066
}
5167
return pkg, nil

0 commit comments

Comments
 (0)