diff --git a/kernel/api/router.go b/kernel/api/router.go index 8799e207d..f41165aa4 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -282,6 +282,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/setting/setEmoji", model.CheckAuth, model.CheckReadonly, setEmoji) ginServer.Handle("POST", "/api/setting/setFlashcard", model.CheckAuth, model.CheckReadonly, setFlashcard) ginServer.Handle("POST", "/api/setting/setAI", model.CheckAuth, model.CheckReadonly, setAI) + ginServer.Handle("POST", "/api/setting/setBazaar", model.CheckAuth, model.CheckReadonly, setBazaar) ginServer.Handle("POST", "/api/graph/resetGraph", model.CheckAuth, model.CheckReadonly, resetGraph) ginServer.Handle("POST", "/api/graph/resetLocalGraph", model.CheckAuth, model.CheckReadonly, resetLocalGraph) diff --git a/kernel/api/setting.go b/kernel/api/setting.go index ba2e925a9..bd45d7bad 100644 --- a/kernel/api/setting.go +++ b/kernel/api/setting.go @@ -29,6 +29,35 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func setBazaar(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + param, err := gulu.JSON.MarshalJSON(arg) + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + bazaar := &conf.Bazaar{} + if err = gulu.JSON.UnmarshalJSON(param, bazaar); nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + model.Conf.Bazaar = bazaar + model.Conf.Save() + + ret.Data = bazaar +} + func setAI(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/conf/bazaar.go b/kernel/conf/bazaar.go new file mode 100644 index 000000000..dbd0f43f3 --- /dev/null +++ b/kernel/conf/bazaar.go @@ -0,0 +1,27 @@ +// SiYuan - Build Your Eternal Digital Garden +// Copyright (c) 2020-present, b3log.org +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . + +package conf + +type Bazaar struct { + Trust bool `json:"bool"` +} + +func NewBazaar() *Bazaar { + return &Bazaar{ + Trust: false, + } +} diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 8fe8dc65f..495274b16 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -72,6 +72,7 @@ type AppConf struct { Search *conf.Search `json:"search"` // 搜索配置 Flashcard *conf.Flashcard `json:"flashcard"` // 闪卡配置 AI *conf.AI `json:"ai"` // 人工智能配置 + Bazaar *conf.Bazaar `json:"bazaar"` // 集市配置 Stat *conf.Stat `json:"stat"` // 统计 Api *conf.API `json:"api"` // API Repo *conf.Repo `json:"repo"` // 数据仓库 @@ -288,6 +289,10 @@ func InitConf() { Conf.Api = conf.NewAPI() } + if nil == Conf.Bazaar { + Conf.Bazaar = conf.NewBazaar() + } + if nil == Conf.Repo { Conf.Repo = conf.NewRepo() }