🎨 Support export and import settings https://github.com/siyuan-note/siyuan/issues/10617
This commit is contained in:
parent
a74266bf6b
commit
694303e5e8
1 changed files with 20 additions and 4 deletions
|
@ -346,15 +346,15 @@ func importConf(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
tmpDir := filepath.Join(util.TempDir, "import")
|
||||
if err = os.MkdirAll(tmpDir, 0755); err != nil {
|
||||
importDir := filepath.Join(util.TempDir, "import")
|
||||
if err = os.MkdirAll(importDir, 0755); err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
tmp := filepath.Join(tmpDir, f.Filename)
|
||||
tmp := filepath.Join(importDir, f.Filename)
|
||||
if err = os.WriteFile(tmp, data, 0644); err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
|
@ -362,6 +362,7 @@ func importConf(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
tmpDir := filepath.Join(importDir, "conf")
|
||||
if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
|
@ -369,7 +370,22 @@ func importConf(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
tmp = filepath.Join(tmpDir, f.Filename[:len(f.Filename)-4])
|
||||
entries, err := os.ReadDir(tmpDir)
|
||||
if err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
if 1 != len(entries) {
|
||||
logging.LogErrorf("invalid conf package")
|
||||
ret.Code = -1
|
||||
ret.Msg = "invalid conf package"
|
||||
return
|
||||
}
|
||||
|
||||
tmp = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(tmp)
|
||||
if err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue