diff --git a/pkg/models/openpitrix/applications.go b/pkg/models/openpitrix/applications.go index 8f82ddff9..7c1c6bbe0 100644 --- a/pkg/models/openpitrix/applications.go +++ b/pkg/models/openpitrix/applications.go @@ -16,6 +16,7 @@ package openpitrix import ( "bytes" "context" + "encoding/base64" "errors" "fmt" "sort" @@ -104,7 +105,7 @@ func newApplicationOperator(cached reposcache.ReposCache, informers externalvers } // save icon data and helm application -func (c *applicationOperator) createApp(app *v1alpha1.HelmApplication, iconData []byte) (*v1alpha1.HelmApplication, error) { +func (c *applicationOperator) createApp(app *v1alpha1.HelmApplication, iconData string) (*v1alpha1.HelmApplication, error) { exists, err := c.getHelmAppByName(app.GetWorkspace(), app.GetTrueName()) if err != nil { return nil, err @@ -112,11 +113,18 @@ func (c *applicationOperator) createApp(app *v1alpha1.HelmApplication, iconData if exists != nil { return nil, appItemExists } - - if len(iconData) != 0 { + if strings.HasPrefix(iconData, "http://") || strings.HasPrefix(iconData, "https://") { + app.Spec.Icon = iconData + } else if len(iconData) != 0 { // save icon attachment iconId := idutils.GetUuid(v1alpha1.HelmAttachmentPrefix) - err = c.backingStoreClient.Upload(iconId, iconId, bytes.NewBuffer(iconData), len(iconData)) + decodeString, err := base64.StdEncoding.DecodeString(iconData) + if err != nil { + klog.Errorf("decodeString icon failed, error: %s", err) + return nil, err + } + + err = c.backingStoreClient.Upload(iconId, iconId, bytes.NewBuffer(decodeString), len(iconData)) if err != nil { klog.Errorf("save icon attachment failed, error: %s", err) return nil, err @@ -168,6 +176,7 @@ func (c *applicationOperator) ValidatePackage(request *ValidatePackageRequest) ( result.VersionName = chrt.GetVersionName() result.Description = chrt.GetDescription() result.URL = chrt.GetUrls() + result.Icon = chrt.GetIcon() } return result, nil diff --git a/pkg/models/openpitrix/types.go b/pkg/models/openpitrix/types.go index 3ccddcb65..9eb289562 100644 --- a/pkg/models/openpitrix/types.go +++ b/pkg/models/openpitrix/types.go @@ -288,7 +288,7 @@ type AppVersionReview struct { type CreateAppRequest struct { // app icon - Icon strfmt.Base64 `json:"icon,omitempty"` + Icon string `json:"icon,omitempty"` // isv Isv string `json:"isv,omitempty"` @@ -413,6 +413,8 @@ type ValidatePackageResponse struct { // app version name.eg.[0.1.0] VersionName string `json:"version_name,omitempty"` + + Icon string `json:"icon,omitempty"` } type CreateAppVersionRequest struct {