A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(siteinfo): fix Manifest: property 'icons' ignored, type array expected.
LinkinStarsde58e527e458
diff --git a/internal/controller/siteinfo_controller.go b/internal/controller/siteinfo_controller.goindex 5b19ae76..3ee0e040 100644--- a/internal/controller/siteinfo_controller.go+++ b/internal/controller/siteinfo_controller.go@@ -133,12 +133,7 @@ func (sc *SiteInfoController) GetManifestJson(ctx *gin.Context) {Revision: constant.Revision,ShortName: "Answer",Name: "answer.apache.org",- Icons: map[string]string{- "16": favicon,- "32": favicon,- "48": favicon,- "128": favicon,- },+ Icons: schema.CreateManifestJsonIcons(favicon),StartUrl: ".",Display: "standalone",ThemeColor: "#000000",@@ -148,10 +143,7 @@ func (sc *SiteInfoController) GetManifestJson(ctx *gin.Context) {if err != nil {log.Error(err)} else if len(branding.Favicon) > 0 {- resp.Icons["16"] = branding.Favicon- resp.Icons["32"] = branding.Favicon- resp.Icons["48"] = branding.Favicon- resp.Icons["128"] = branding.Favicon+ resp.Icons = schema.CreateManifestJsonIcons(branding.Favicon)}siteGeneral, err := sc.siteInfoService.GetSiteGeneral(ctx)if err != nil {diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.goindex 264ddb99..d71ea263 100644--- a/internal/schema/siteinfo_schema.go+++ b/internal/schema/siteinfo_schema.go@@ -24,6 +24,7 @@ import ("fmt""net/mail""net/url"+ "path/filepath""strings""github.com/apache/answer/internal/base/constant"@@ -305,16 +306,54 @@ type GetSMTPConfigResp struct {// GetManifestJsonResp get manifest json responsetype GetManifestJsonResp struct {- ManifestVersion int `json:"manifest_version"`- Version string `json:"version"`- Revision string `json:"revision"`- ShortName string `json:"short_name"`- Name string `json:"name"`- Icons map[string]string `json:"icons"`- StartUrl string `json:"start_url"`- Display string `json:"display"`- ThemeColor string `json:"theme_color"`- BackgroundColor string `json:"background_color"`+ ManifestVersion int `json:"manifest_version"`+ Version string `json:"version"`+ Revision string `json:"revision"`+ ShortName string `json:"short_name"`+ Name string `json:"name"`+ Icons []ManifestJsonIcon `json:"icons"`+ StartUrl string `json:"start_url"`+ Display string `json:"display"`+ ThemeColor string `json:"theme_color"`+ BackgroundColor string `json:"background_color"`+}++type ManifestJsonIcon struct {+ Src string `json:"src"`+ Sizes string `json:"sizes"`+ Type string `json:"type"`+}++func CreateManifestJsonIcons(icon string) []ManifestJsonIcon {+ ext := filepath.Ext(icon)+ if ext == "" {+ ext = "png"+ } else {+ ext = strings.ToLower(ext[1:])+ }+ iconType := fmt.Sprintf("image/%s", ext)+ return []ManifestJsonIcon{+ {+ Src: icon,+ Sizes: "16x16",+ Type: iconType,+ },+ {+ Src: icon,+ Sizes: "32x32",+ Type: iconType,+ },+ {+ Src: icon,+ Sizes: "48x48",+ Type: iconType,+ },+ {+ Src: icon,+ Sizes: "128x128",+ Type: iconType,+ },+ }}const (