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.
feat: support for manifest.json dynamic rendering
LinkinStar995510595b6a
diff --git a/cmd/answer/wire_gen.go b/cmd/answer/wire_gen.goindex 852fd015..aa4e9c5b 100644--- a/cmd/answer/wire_gen.go+++ b/cmd/answer/wire_gen.go@@ -193,7 +193,7 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,activityController := controller.NewActivityController(activityCommon, activityService)answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController)swaggerRouter := router.NewSwaggerRouter(swaggerConf)- uiRouter := router.NewUIRouter()+ uiRouter := router.NewUIRouter(siteinfoController)authUserMiddleware := middleware.NewAuthUserMiddleware(authService)avatarMiddleware := middleware.NewAvatarMiddleware(serviceConf, uploaderService)ginEngine := server.NewHTTPServer(debug, staticRouter, answerAPIRouter, swaggerRouter, uiRouter, authUserMiddleware, avatarMiddleware)diff --git a/internal/controller/siteinfo_controller.go b/internal/controller/siteinfo_controller.goindex 80d6faa7..6337b133 100644--- a/internal/controller/siteinfo_controller.go+++ b/internal/controller/siteinfo_controller.go@@ -1,6 +1,8 @@package controllerimport (+ "net/http"+"github.com/answerdev/answer/internal/base/handler""github.com/answerdev/answer/internal/schema""github.com/answerdev/answer/internal/service/siteinfo_common"@@ -73,3 +75,27 @@ func (sc *SiteinfoController) GetSiteLegalInfo(ctx *gin.Context) {}handler.HandleResponse(ctx, nil, resp)}++// GetManifestJson get manifest.json+func (sc *SiteinfoController) GetManifestJson(ctx *gin.Context) {+ resp := &schema.GetManifestJsonResp{+ ShortName: "Answer",+ Name: "Answer.dev",+ Icons: map[string]string{+ "src": "favicon.ico",+ "sizes": "64x64 32x32 24x24 16x16",+ "type": "image/x-icon",+ },+ StartUrl: ".",+ Display: "standalone",+ ThemeColor: "#000000",+ BackgroundColor: "#ffffff",+ }+ branding, err := sc.siteInfoService.GetSiteBranding(ctx)+ if err != nil {+ log.Error(err)+ } else if len(branding.Favicon) > 0 {+ resp.Icons["scr"] = branding.Favicon+ }+ ctx.JSON(http.StatusOK, resp)+}diff --git a/internal/router/ui.go b/internal/router/ui.goindex 6f0e174f..1255d6ce 100644--- a/internal/router/ui.go+++ b/internal/router/ui.go@@ -7,6 +7,7 @@ import ("net/http""os"+ "github.com/answerdev/answer/internal/controller""github.com/answerdev/answer/ui""github.com/gin-gonic/gin""github.com/segmentfault/pacman/log"@@ -18,11 +19,12 @@ const UIStaticPath = "build/static"// UIRouter is an interface that provides ui static file routerstype UIRouter struct {+ siteInfoController *controller.SiteinfoController}// NewUIRouter creates a new UIRouter instance with the embed resources-func NewUIRouter() *UIRouter {- return &UIRouter{}+func NewUIRouter(siteInfoController *controller.SiteinfoController) *UIRouter {+ return &UIRouter{siteInfoController: siteInfoController}}// _resource is an interface that provides static file, it's a private interface@@ -75,7 +77,9 @@ func (a *UIRouter) Register(r *gin.Engine) {c.Header("content-type", "image/vnd.microsoft.icon")filePath = UIRootFilePath + urlPathcase "/manifest.json":- filePath = UIRootFilePath + urlPath+ // filePath = UIRootFilePath + urlPath+ a.siteInfoController.GetManifestJson(c)+ returncase "/install":// if answer is running by run command user can not access install page.c.Redirect(http.StatusFound, "/")diff --git a/internal/schema/siteinfo_schema.go b/internal/schema/siteinfo_schema.goindex d1292623..637b3bd6 100644--- a/internal/schema/siteinfo_schema.go+++ b/internal/schema/siteinfo_schema.go@@ -120,3 +120,14 @@ type GetSMTPConfigResp struct {SMTPPassword string `json:"smtp_password"`SMTPAuthentication bool `json:"smtp_authentication"`}++// GetManifestJsonResp get manifest json response+type GetManifestJsonResp struct {+ 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"`+}