mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve importing conf https://github.com/siyuan-note/siyuan/issues/13767
This commit is contained in:
parent
288f0a1028
commit
a83d4f2bef
1 changed files with 22 additions and 9 deletions
|
|
@ -28,7 +28,6 @@ import (
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute"
|
"github.com/88250/lute"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/copier"
|
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||||
"github.com/siyuan-note/siyuan/kernel/model"
|
"github.com/siyuan-note/siyuan/kernel/model"
|
||||||
|
|
@ -266,8 +265,15 @@ func exportConf(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data, err := gulu.JSON.MarshalJSON(model.Conf)
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
clonedConf := &model.AppConf{}
|
clonedConf := &model.AppConf{}
|
||||||
if err := copier.CopyWithOption(clonedConf, model.Conf, copier.Option{IgnoreEmpty: false, DeepCopy: true}); err != nil {
|
if err = gulu.JSON.UnmarshalJSON(data, clonedConf); err != nil {
|
||||||
logging.LogErrorf("export conf failed: %s", err)
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
ret.Msg = err.Error()
|
ret.Msg = err.Error()
|
||||||
|
|
@ -305,7 +311,7 @@ func exportConf(c *gin.Context) {
|
||||||
clonedConf.CloudRegion = 0
|
clonedConf.CloudRegion = 0
|
||||||
clonedConf.DataIndexState = 0
|
clonedConf.DataIndexState = 0
|
||||||
|
|
||||||
data, err := gulu.JSON.MarshalIndentJSON(clonedConf, "", " ")
|
data, err = gulu.JSON.MarshalIndentJSON(clonedConf, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logging.LogErrorf("export conf failed: %s", err)
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
ret.Code = -1
|
ret.Code = -1
|
||||||
|
|
@ -461,12 +467,19 @@ func importConf(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = copier.CopyWithOption(model.Conf, importedConf, copier.Option{IgnoreEmpty: true, DeepCopy: true}); err != nil {
|
model.Conf.FileTree = importedConf.FileTree
|
||||||
logging.LogErrorf("import conf failed: %s", err)
|
model.Conf.Tag = importedConf.Tag
|
||||||
ret.Code = -1
|
model.Conf.Editor = importedConf.Editor
|
||||||
ret.Msg = err.Error()
|
model.Conf.Export = importedConf.Export
|
||||||
return
|
model.Conf.Graph = importedConf.Graph
|
||||||
}
|
model.Conf.UILayout = importedConf.UILayout
|
||||||
|
model.Conf.System = importedConf.System
|
||||||
|
model.Conf.Keymap = importedConf.Keymap
|
||||||
|
model.Conf.Search = importedConf.Search
|
||||||
|
model.Conf.Flashcard = importedConf.Flashcard
|
||||||
|
model.Conf.AI = importedConf.AI
|
||||||
|
model.Conf.Bazaar = importedConf.Bazaar
|
||||||
|
model.Conf.Save()
|
||||||
|
|
||||||
logging.LogInfof("imported conf")
|
logging.LogInfof("imported conf")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue