Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
feat(conf): Support control Frontend Conf by Backend.
Browse files Browse the repository at this point in the history
Signed-off-by: qwqcode <[email protected]>
  • Loading branch information
qwqcode committed Apr 25, 2022
1 parent fd1be63 commit 05ad1c4
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
26 changes: 26 additions & 0 deletions artalk-go.frontend.example.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
frontend:
placeholder: "键入内容..."
noComment: "「此时无声胜有声」"
sendBtn: "发送评论"
darkMode: false
editorTravel: true
emoticons: "https://cdn.jsdelivr.net/gh/ArtalkJS/Emoticons/grps/default.json"
vote: true
voteDown: false
uaBadge: true
listSort: true
pvEl: "#ArtalkPV"
flatMode: "auto"
maxNesting: 3
gravatar:
default: "mp"
mirror: "https://sdn.geekzu.org/avatar/"
pagination:
pageSize: 20
readMore: true
autoLoad: true
heightLimit:
content: 300
children: 400
reqTimeout: 15000
versionCheck: true
34 changes: 34 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
Email EmailConf `mapstructure:"email" json:"email"` // 邮箱提醒
ImgUpload ImgUploadConf `mapstructure:"img_upload" json:"img_upload"` // 图片上传
Notify NotifyConf `mapstructure:"notify" json:"notify"` // 其他通知方式
Frontend FrontendConf `mapstructure:"frontend" json:"frontend"`
}

type DBConf struct {
Expand Down Expand Up @@ -256,3 +257,36 @@ type NotifyLINEConf struct {
ChannelAccessToken string `mapstructure:"channel_access_token" json:"channel_access_token"`
Receivers []string `mapstructure:"receivers" json:"receivers"`
}

// 使用转换 @link https://transform.tools/json-to-go
type FrontendConf struct {
Placeholder string `mapstructure:"placeholder" json:"placeholder,omitempty"`
NoComment string `mapstructure:"noComment" json:"noComment,omitempty"`
SendBtn string `mapstructure:"sendBtn" json:"sendBtn,omitempty"`
DarkMode bool `mapstructure:"darkMode" json:"darkMode,omitempty"`
EditorTravel bool `mapstructure:"editorTravel" json:"editorTravel,omitempty"`
Emoticons string `mapstructure:"emoticons" json:"emoticons,omitempty"`
Vote bool `mapstructure:"vote" json:"vote,omitempty"`
VoteDown bool `mapstructure:"voteDown" json:"voteDown,omitempty"`
UaBadge bool `mapstructure:"uaBadge" json:"uaBadge,omitempty"`
ListSort bool `mapstructure:"listSort" json:"listSort,omitempty"`
PvEl string `mapstructure:"pvEl" json:"pvEl,omitempty"`
FlatMode string `mapstructure:"flatMode" json:"flatMode,omitempty"`
MaxNesting int `mapstructure:"maxNesting" json:"maxNesting,omitempty"`
Gravatar struct {
Default string `mapstructure:"default" json:"default,omitempty"`
Mirror string `mapstructure:"mirror" json:"mirror,omitempty"`
} `mapstructure:"gravatar" json:"gravatar,omitempty"`
Pagination struct {
PageSize int `mapstructure:"pageSize" json:"pageSize,omitempty"`
ReadMore bool `mapstructure:"readMore" json:"readMore,omitempty"`
AutoLoad bool `mapstructure:"autoLoad" json:"autoLoad,omitempty"`
} `mapstructure:"pagination" json:"pagination,omitempty"`
HeightLimit struct {
Content int `mapstructure:"content" json:"content,omitempty"`
Children int `mapstructure:"children" json:"children,omitempty"`
} `mapstructure:"heightLimit" json:"heightLimit,omitempty"`
ImgUpload bool `mapstructure:"imgUpload" json:"imgUpload,omitempty"`
ReqTimeout int `mapstructure:"reqTimeout" json:"reqTimeout,omitempty"`
VersionCheck bool `mapstructure:"versionCheck" json:"versionCheck,omitempty"`
}
2 changes: 1 addition & 1 deletion http/a_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func InitRouter(e *echo.Echo) {

// conf
api.Any("/conf", func(c echo.Context) error {
return c.JSON(200, GetApiPublicConfDataMap(c))
return RespData(c, GetApiPublicConfDataMap(c))
})

// version
Expand Down
6 changes: 5 additions & 1 deletion http/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ func GetApiPublicConfDataMap(c echo.Context) Map {
imgUpload = true // 管理员始终允许上传图片
}

frontendConf := config.Instance.Frontend
frontendConf.ImgUpload = imgUpload

return Map{
"img_upload": imgUpload,
"img_upload": imgUpload,
"frontend_conf": frontendConf,
}
}

0 comments on commit 05ad1c4

Please sign in to comment.