This is an automated email from the ASF dual-hosted git repository.

linkinstar pushed a commit to branch feat/1.4.5/file
in repository https://gitbox.apache.org/repos/asf/answer.git


The following commit(s) were added to refs/heads/feat/1.4.5/file by this push:
     new de58e527 fix(siteinfo): fix Manifest: property 'icons' ignored, type 
array expected.
de58e527 is described below

commit de58e527e458151724a4ab531aeeb46b2d56a6cd
Author: LinkinStars <[email protected]>
AuthorDate: Tue Mar 4 14:23:23 2025 +0800

    fix(siteinfo): fix Manifest: property 'icons' ignored, type array expected.
---
 internal/controller/siteinfo_controller.go | 12 +-----
 internal/schema/siteinfo_schema.go         | 59 +++++++++++++++++++++++++-----
 2 files changed, 51 insertions(+), 20 deletions(-)

diff --git a/internal/controller/siteinfo_controller.go 
b/internal/controller/siteinfo_controller.go
index 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.go
index 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 response
 type 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 (

Reply via email to