diff --git a/models/migration.go b/models/migration.go index a877648..2930fa1 100644 --- a/models/migration.go +++ b/models/migration.go @@ -178,6 +178,12 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti {Name: "captcha_CaptchaLen", Value: "6", Type: "captcha"}, {Name: "thumb_width", Value: "400", Type: "thumb"}, {Name: "thumb_height", Value: "300", Type: "thumb"}, + {Name: "pwa_small_icon", Value: "/static/img/favicon.ico", Type: "pwa"}, + {Name: "pwa_medium_icon", Value: "/static/img/logo192.png", Type: "pwa"}, + {Name: "pwa_large_icon", Value: "/static/img/logo512.png", Type: "pwa"}, + {Name: "pwa_display", Value: "standalone", Type: "pwa"}, + {Name: "pwa_theme_color", Value: "#000000", Type: "pwa"}, + {Name: "pwa_background_color", Value: "#ffffff", Type: "pwa"}, } for _, value := range defaultSettings { diff --git a/routers/controllers/admin.go b/routers/controllers/admin.go index f81aeab..ce930b9 100644 --- a/routers/controllers/admin.go +++ b/routers/controllers/admin.go @@ -35,3 +35,14 @@ func AdminChangeSetting(c *gin.Context) { c.JSON(200, ErrorResponse(err)) } } + +// AdminGetSetting 获取站点设置 +func AdminGetSetting(c *gin.Context) { + var service admin.BatchSettingGet + if err := c.ShouldBindJSON(&service); err == nil { + res := service.Get() + c.JSON(200, res) + } else { + c.JSON(200, ErrorResponse(err)) + } +} diff --git a/routers/controllers/site.go b/routers/controllers/site.go index 086b66c..78f28ea 100644 --- a/routers/controllers/site.go +++ b/routers/controllers/site.go @@ -85,3 +85,43 @@ func Captcha(c *gin.Context) { Data: base64stringD, }) } + +// Manifest 获取manifest.json +func Manifest(c *gin.Context) { + options := model.GetSettingByNames( + "siteName", + "siteTitle", + "pwa_small_icon", + "pwa_medium_icon", + "pwa_large_icon", + "pwa_display", + "pwa_theme_color", + "pwa_background_color", + ) + + c.JSON(200, map[string]interface{}{ + "short_name": options["siteName"], + "name": options["siteTitle"], + "icons": []map[string]string{ + { + "src": options["pwa_small_icon"], + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon", + }, + { + "src": options["pwa_medium_icon"], + "type": "image/png", + "sizes": "192x192", + }, + { + "src": options["pwa_large_icon"], + "type": "image/png", + "sizes": "512x512", + }, + }, + "start_url": ".", + "display": options["pwa_display"], + "theme_color": options["pwa_theme_color"], + "background_color": options["pwa_background_color"], + }) +} diff --git a/routers/router.go b/routers/router.go index 63bc323..a571634 100644 --- a/routers/router.go +++ b/routers/router.go @@ -72,6 +72,12 @@ func InitCORS(router *gin.Engine) { func InitMasterRouter() *gin.Engine { r := gin.Default() bootstrap.InitCustomRoute(r.Group("/custom")) + + /* + 静态资源 + */ + r.GET("manifest.json", controllers.Manifest) + v3 := r.Group("/api/v3") /* @@ -289,6 +295,8 @@ func InitMasterRouter() *gin.Engine { admin.GET("news", controllers.AdminNews) // 更改设置 admin.PATCH("setting", controllers.AdminChangeSetting) + // 获取设置 + admin.POST("setting", controllers.AdminGetSetting) } // 用户 diff --git a/service/admin/site.go b/service/admin/site.go index 834f01a..b8d9681 100644 --- a/service/admin/site.go +++ b/service/admin/site.go @@ -23,6 +23,17 @@ type SettingChangeService struct { Value string `json:"value"` } +// BatchSettingGet 设定批量获取服务 +type BatchSettingGet struct { + Keys []string `json:"keys"` +} + +// Get 获取设定值 +func (service *BatchSettingGet) Get() serializer.Response { + options := model.GetSettingByNames(service.Keys...) + return serializer.Response{Data: options} +} + // Change 批量更改站点设定 func (service *BatchSettingChangeService) Change() serializer.Response { for _, setting := range service.Options {