Feat: dynamically generate manifest.json
This commit is contained in:
parent
31d4a0e1c2
commit
04d13bd071
5 changed files with 76 additions and 0 deletions
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"],
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
// 用户
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue