Skip to content

Commit 3acc19c

Browse files
committed
Merge remote-tracking branch 'origin/feat/1.4.5/file' into test
2 parents d1eac6e + de58e52 commit 3acc19c

File tree

2 files changed

+51
-20
lines changed

2 files changed

+51
-20
lines changed

internal/controller/siteinfo_controller.go

+2-10
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,7 @@ func (sc *SiteInfoController) GetManifestJson(ctx *gin.Context) {
133133
Revision: constant.Revision,
134134
ShortName: "Answer",
135135
Name: "answer.apache.org",
136-
Icons: map[string]string{
137-
"16": favicon,
138-
"32": favicon,
139-
"48": favicon,
140-
"128": favicon,
141-
},
136+
Icons: schema.CreateManifestJsonIcons(favicon),
142137
StartUrl: ".",
143138
Display: "standalone",
144139
ThemeColor: "#000000",
@@ -148,10 +143,7 @@ func (sc *SiteInfoController) GetManifestJson(ctx *gin.Context) {
148143
if err != nil {
149144
log.Error(err)
150145
} else if len(branding.Favicon) > 0 {
151-
resp.Icons["16"] = branding.Favicon
152-
resp.Icons["32"] = branding.Favicon
153-
resp.Icons["48"] = branding.Favicon
154-
resp.Icons["128"] = branding.Favicon
146+
resp.Icons = schema.CreateManifestJsonIcons(branding.Favicon)
155147
}
156148
siteGeneral, err := sc.siteInfoService.GetSiteGeneral(ctx)
157149
if err != nil {

internal/schema/siteinfo_schema.go

+49-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"fmt"
2525
"net/mail"
2626
"net/url"
27+
"path/filepath"
2728
"strings"
2829

2930
"github.com/apache/answer/internal/base/constant"
@@ -305,16 +306,54 @@ type GetSMTPConfigResp struct {
305306

306307
// GetManifestJsonResp get manifest json response
307308
type GetManifestJsonResp struct {
308-
ManifestVersion int `json:"manifest_version"`
309-
Version string `json:"version"`
310-
Revision string `json:"revision"`
311-
ShortName string `json:"short_name"`
312-
Name string `json:"name"`
313-
Icons map[string]string `json:"icons"`
314-
StartUrl string `json:"start_url"`
315-
Display string `json:"display"`
316-
ThemeColor string `json:"theme_color"`
317-
BackgroundColor string `json:"background_color"`
309+
ManifestVersion int `json:"manifest_version"`
310+
Version string `json:"version"`
311+
Revision string `json:"revision"`
312+
ShortName string `json:"short_name"`
313+
Name string `json:"name"`
314+
Icons []ManifestJsonIcon `json:"icons"`
315+
StartUrl string `json:"start_url"`
316+
Display string `json:"display"`
317+
ThemeColor string `json:"theme_color"`
318+
BackgroundColor string `json:"background_color"`
319+
}
320+
321+
type ManifestJsonIcon struct {
322+
Src string `json:"src"`
323+
Sizes string `json:"sizes"`
324+
Type string `json:"type"`
325+
}
326+
327+
func CreateManifestJsonIcons(icon string) []ManifestJsonIcon {
328+
ext := filepath.Ext(icon)
329+
if ext == "" {
330+
ext = "png"
331+
} else {
332+
ext = strings.ToLower(ext[1:])
333+
}
334+
iconType := fmt.Sprintf("image/%s", ext)
335+
return []ManifestJsonIcon{
336+
{
337+
Src: icon,
338+
Sizes: "16x16",
339+
Type: iconType,
340+
},
341+
{
342+
Src: icon,
343+
Sizes: "32x32",
344+
Type: iconType,
345+
},
346+
{
347+
Src: icon,
348+
Sizes: "48x48",
349+
Type: iconType,
350+
},
351+
{
352+
Src: icon,
353+
Sizes: "128x128",
354+
Type: iconType,
355+
},
356+
}
318357
}
319358

320359
const (

0 commit comments

Comments
 (0)