This commit is contained in:
Liang Ding 2022-10-12 09:13:40 +08:00
parent ee413a6352
commit 5aa5764974
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 6 additions and 8 deletions

View file

@ -42,8 +42,9 @@ func getSnippet(c *gin.Context) {
enabled = false
}
confSnippets := model.LoadSnippets()
var snippets []*conf.Snippet
for _, s := range model.Snippets {
for _, s := range confSnippets {
if ("all" == typ || s.Type == typ) && (2 == enabledArg || s.Enabled == enabled) {
snippets = append(snippets, s)
}

View file

@ -285,7 +285,6 @@ func InitConf() {
}
util.SetNetworkProxy(Conf.System.NetworkProxy.String())
loadSnippets()
}
var langs = map[string]map[int]string{}
@ -661,10 +660,8 @@ func clearWorkspaceTemp() {
logging.LogInfof("cleared workspace temp")
}
var Snippets []*conf.Snippet // js/css 代码片段配置
func loadSnippets() {
Snippets = []*conf.Snippet{}
func LoadSnippets() (ret []*conf.Snippet) {
ret = []*conf.Snippet{}
confPath := filepath.Join(util.DataDir, "snippets/conf.json")
if !gulu.File.IsExist(confPath) {
@ -677,10 +674,10 @@ func loadSnippets() {
return
}
if err = gulu.JSON.UnmarshalJSON(data, &Snippets); nil != err {
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
logging.LogErrorf("unmarshal js snippets failed: %s", err)
return
}
logging.LogInfof("loaded js snippets [%d]", len(Snippets))
logging.LogInfof("loaded js snippets [%d]", len(ret))
return
}