mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
🎨 Support export and import settings https://github.com/siyuan-note/siyuan/issues/10617
This commit is contained in:
parent
c8007a5488
commit
b2f1e873b7
2 changed files with 93 additions and 0 deletions
|
|
@ -62,6 +62,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||||
ginServer.Handle("POST", "/api/system/exportLog", model.CheckAuth, model.CheckAdminRole, exportLog)
|
ginServer.Handle("POST", "/api/system/exportLog", model.CheckAuth, model.CheckAdminRole, exportLog)
|
||||||
ginServer.Handle("POST", "/api/system/getChangelog", model.CheckAuth, getChangelog)
|
ginServer.Handle("POST", "/api/system/getChangelog", model.CheckAuth, getChangelog)
|
||||||
ginServer.Handle("POST", "/api/system/getNetwork", model.CheckAuth, model.CheckAdminRole, getNetwork)
|
ginServer.Handle("POST", "/api/system/getNetwork", model.CheckAuth, model.CheckAdminRole, getNetwork)
|
||||||
|
ginServer.Handle("POST", "/api/system/exportConf", model.CheckAuth, model.CheckAdminRole, exportConf)
|
||||||
|
|
||||||
ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage)
|
ginServer.Handle("POST", "/api/storage/setLocalStorage", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setLocalStorage)
|
||||||
ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)
|
ginServer.Handle("POST", "/api/storage/getLocalStorage", model.CheckAuth, getLocalStorage)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -206,6 +207,97 @@ func exportLog(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func exportConf(c *gin.Context) {
|
||||||
|
ret := gulu.Ret.NewResult()
|
||||||
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
||||||
|
name := "siyuan-conf-" + time.Now().Format("20060102150405") + ".json"
|
||||||
|
tmpDir := filepath.Join(util.TempDir, "export")
|
||||||
|
if err := os.MkdirAll(tmpDir, 0755); err != nil {
|
||||||
|
logging.LogErrorf("export WebDAV provider failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
clonedConf := &model.AppConf{}
|
||||||
|
if err := copier.Copy(clonedConf, model.Conf); err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if nil != clonedConf.Editor {
|
||||||
|
clonedConf.Editor.Emoji = []string{}
|
||||||
|
}
|
||||||
|
if nil != clonedConf.Export {
|
||||||
|
clonedConf.Export.PandocBin = ""
|
||||||
|
}
|
||||||
|
clonedConf.UserData = ""
|
||||||
|
clonedConf.Account = nil
|
||||||
|
clonedConf.AccessAuthCode = ""
|
||||||
|
if nil != clonedConf.System {
|
||||||
|
clonedConf.System.ID = ""
|
||||||
|
clonedConf.System.Name = ""
|
||||||
|
clonedConf.System.OSPlatform = ""
|
||||||
|
clonedConf.System.Container = ""
|
||||||
|
clonedConf.System.IsMicrosoftStore = false
|
||||||
|
clonedConf.System.IsInsider = false
|
||||||
|
}
|
||||||
|
clonedConf.Sync = nil
|
||||||
|
clonedConf.Stat = nil
|
||||||
|
clonedConf.Api = nil
|
||||||
|
clonedConf.Repo = nil
|
||||||
|
clonedConf.Publish = nil
|
||||||
|
clonedConf.CloudRegion = 0
|
||||||
|
clonedConf.DataIndexState = 0
|
||||||
|
|
||||||
|
data, err := gulu.JSON.MarshalIndentJSON(clonedConf, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmp := filepath.Join(tmpDir, name)
|
||||||
|
if err = os.WriteFile(tmp, data, 0644); err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
zipFile, err := gulu.Zip.Create(tmp + ".zip")
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = zipFile.AddEntry(name, tmp); err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = zipFile.Close(); err != nil {
|
||||||
|
logging.LogErrorf("export conf failed: %s", err)
|
||||||
|
ret.Code = -1
|
||||||
|
ret.Msg = err.Error()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
zipPath := "/export/" + name + ".zip"
|
||||||
|
ret.Data = map[string]interface{}{
|
||||||
|
"name": name,
|
||||||
|
"zip": zipPath,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getConf(c *gin.Context) {
|
func getConf(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue