Skip to content

Commit

Permalink
[release-3.3] fix the issue that the upload app template did not disp…
Browse files Browse the repository at this point in the history
…lay icons (#5493)

fix the issue that the upload app template did not display icons

Co-authored-by: xiaoliu <978911210@qq.com>
  • Loading branch information
ks-ci-bot and liangzai006 authored Jan 29, 2023
1 parent c8e131f commit d938161
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions pkg/models/openpitrix/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package openpitrix
import (
"bytes"
"context"
"encoding/base64"
"errors"
"fmt"
"sort"
Expand Down Expand Up @@ -104,19 +105,26 @@ 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
}
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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/models/openpitrix/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d938161

Please sign in to comment.