mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-07-03 14:09:06 +02:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
@@ -79,7 +79,7 @@ export class MobileFiles extends Model {
|
||||
this.selectItem(data.data.box.id, data.data.path);
|
||||
break;
|
||||
case "renamenotebook":
|
||||
this.element.querySelector(`[data-url="${data.data.box}"] .b3-list-item__text`).innerHTML = data.data.name;
|
||||
this.element.querySelector(`[data-url="${data.data.box}"] .b3-list-item__text`).innerHTML = escapeHtml(data.data.name);
|
||||
break;
|
||||
case "rename":
|
||||
this.onRename(data.data);
|
||||
|
||||
+40
-4
@@ -17,6 +17,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -68,8 +69,17 @@ func importSY(c *gin.Context) {
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
writePath := filepath.Join(util.TempDir, "import", file.Filename)
|
||||
|
||||
writePath := filepath.Join(importDir, file.Filename)
|
||||
if !util.IsSubPath(importDir, writePath) {
|
||||
logging.LogErrorf("import path [%s] is not sub path of import dir [%s]", writePath, importDir)
|
||||
ret.Code = -1
|
||||
ret.Msg = "import path is not sub path of import dir"
|
||||
return
|
||||
}
|
||||
|
||||
defer os.RemoveAll(writePath)
|
||||
|
||||
writer, err := os.OpenFile(writePath, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
logging.LogErrorf("open import .sy.zip [%s] failed: %s", writePath, err)
|
||||
@@ -119,14 +129,14 @@ func importData(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmpImport := filepath.Join(util.TempDir, "import")
|
||||
err = os.MkdirAll(tmpImport, 0755)
|
||||
importDir := filepath.Join(util.TempDir, "import")
|
||||
err = os.MkdirAll(importDir, 0755)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = "create temp import dir failed"
|
||||
return
|
||||
}
|
||||
dataZipPath := filepath.Join(tmpImport, util.CurrentTimeSecondsStr()+".zip")
|
||||
dataZipPath := filepath.Join(importDir, util.CurrentTimeSecondsStr()+".zip")
|
||||
defer os.RemoveAll(dataZipPath)
|
||||
dataZipFile, err := os.Create(dataZipPath)
|
||||
if err != nil {
|
||||
@@ -179,6 +189,23 @@ func importStdMd(c *gin.Context) {
|
||||
notebook := arg["notebook"].(string)
|
||||
localPath := arg["localPath"].(string)
|
||||
toPath := arg["toPath"].(string)
|
||||
|
||||
if util.IsSubPath(util.WorkingDir, localPath) {
|
||||
msg := fmt.Sprintf("import from local path [%s] failed: local path is sub path of working dir", localPath)
|
||||
logging.LogErrorf(msg)
|
||||
ret.Code = -1
|
||||
ret.Msg = msg
|
||||
return
|
||||
}
|
||||
|
||||
if util.IsSensitivePath(localPath) {
|
||||
msg := fmt.Sprintf("import from local path [%s] failed: local path is sensitive path", localPath)
|
||||
logging.LogErrorf(msg)
|
||||
ret.Code = -1
|
||||
ret.Msg = msg
|
||||
return
|
||||
}
|
||||
|
||||
err := model.ImportFromLocalPath(notebook, localPath, toPath)
|
||||
if err != nil {
|
||||
ret.Code = -1
|
||||
@@ -225,8 +252,17 @@ func importZipMd(c *gin.Context) {
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
writePath := filepath.Join(util.TempDir, "import", file.Filename)
|
||||
if !util.IsSubPath(importDir, writePath) {
|
||||
logging.LogErrorf("import path [%s] is not sub path of import dir [%s]", writePath, importDir)
|
||||
ret.Code = -1
|
||||
ret.Msg = "import path is not sub path of import dir"
|
||||
return
|
||||
}
|
||||
|
||||
defer os.RemoveAll(writePath)
|
||||
|
||||
writer, err := os.OpenFile(writePath, os.O_RDWR|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
logging.LogErrorf("open import .zip [%s] failed: %s", writePath, err)
|
||||
|
||||
+30
-16
@@ -79,8 +79,15 @@ func importSyncProviderWebDAV(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp := filepath.Join(importDir, f.Filename)
|
||||
if err = os.WriteFile(tmp, data, 0644); err != nil {
|
||||
writePath := filepath.Join(importDir, f.Filename)
|
||||
if !util.IsSubPath(importDir, writePath) {
|
||||
logging.LogErrorf("import path [%s] is not sub path of import dir [%s]", writePath, importDir)
|
||||
ret.Code = -1
|
||||
ret.Msg = "import path is not sub path of import dir"
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(writePath, data, 0644); err != nil {
|
||||
logging.LogErrorf("import WebDAV provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@@ -89,15 +96,15 @@ func importSyncProviderWebDAV(c *gin.Context) {
|
||||
|
||||
tmpDir := filepath.Join(importDir, "webdav")
|
||||
os.RemoveAll(tmpDir)
|
||||
if strings.HasSuffix(strings.ToLower(tmp), ".zip") {
|
||||
if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil {
|
||||
if strings.HasSuffix(strings.ToLower(writePath), ".zip") {
|
||||
if err = gulu.Zip.Unzip(writePath, tmpDir); err != nil {
|
||||
logging.LogErrorf("import WebDAV provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
} else if strings.HasSuffix(strings.ToLower(tmp), ".json") {
|
||||
if err = gulu.File.CopyFile(tmp, filepath.Join(tmpDir, f.Filename)); err != nil {
|
||||
} else if strings.HasSuffix(strings.ToLower(writePath), ".json") {
|
||||
if err = gulu.File.CopyFile(writePath, filepath.Join(tmpDir, f.Filename)); err != nil {
|
||||
logging.LogErrorf("import WebDAV provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@@ -124,8 +131,8 @@ func importSyncProviderWebDAV(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(tmp)
|
||||
writePath = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(writePath)
|
||||
if err != nil {
|
||||
logging.LogErrorf("import WebDAV provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
@@ -265,8 +272,15 @@ func importSyncProviderS3(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp := filepath.Join(importDir, f.Filename)
|
||||
if err = os.WriteFile(tmp, data, 0644); err != nil {
|
||||
writePath := filepath.Join(importDir, f.Filename)
|
||||
if !util.IsSubPath(importDir, writePath) {
|
||||
logging.LogErrorf("import path [%s] is not sub path of import dir [%s]", writePath, importDir)
|
||||
ret.Code = -1
|
||||
ret.Msg = "import path is not sub path of import dir"
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(writePath, data, 0644); err != nil {
|
||||
logging.LogErrorf("import S3 provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@@ -275,15 +289,15 @@ func importSyncProviderS3(c *gin.Context) {
|
||||
|
||||
tmpDir := filepath.Join(importDir, "s3")
|
||||
os.RemoveAll(tmpDir)
|
||||
if strings.HasSuffix(strings.ToLower(tmp), ".zip") {
|
||||
if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil {
|
||||
if strings.HasSuffix(strings.ToLower(writePath), ".zip") {
|
||||
if err = gulu.Zip.Unzip(writePath, tmpDir); err != nil {
|
||||
logging.LogErrorf("import S3 provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
} else if strings.HasSuffix(strings.ToLower(tmp), ".json") {
|
||||
if err = gulu.File.CopyFile(tmp, filepath.Join(tmpDir, f.Filename)); err != nil {
|
||||
} else if strings.HasSuffix(strings.ToLower(writePath), ".json") {
|
||||
if err = gulu.File.CopyFile(writePath, filepath.Join(tmpDir, f.Filename)); err != nil {
|
||||
logging.LogErrorf("import S3 provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@@ -310,8 +324,8 @@ func importSyncProviderS3(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(tmp)
|
||||
writePath = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(writePath)
|
||||
if err != nil {
|
||||
logging.LogErrorf("import S3 provider failed: %s", err)
|
||||
ret.Code = -1
|
||||
|
||||
+15
-8
@@ -441,8 +441,15 @@ func importConf(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp := filepath.Join(importDir, f.Filename)
|
||||
if err = os.WriteFile(tmp, data, 0644); err != nil {
|
||||
writePath := filepath.Join(importDir, f.Filename)
|
||||
if !util.IsSubPath(importDir, writePath) {
|
||||
logging.LogErrorf("import path [%s] is not sub path of import dir [%s]", writePath, importDir)
|
||||
ret.Code = -1
|
||||
ret.Msg = "import path is not sub path of import dir"
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.WriteFile(writePath, data, 0644); err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@@ -451,15 +458,15 @@ func importConf(c *gin.Context) {
|
||||
|
||||
tmpDir := filepath.Join(importDir, "conf")
|
||||
os.RemoveAll(tmpDir)
|
||||
if strings.HasSuffix(strings.ToLower(tmp), ".zip") {
|
||||
if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil {
|
||||
if strings.HasSuffix(strings.ToLower(writePath), ".zip") {
|
||||
if err = gulu.Zip.Unzip(writePath, tmpDir); err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
} else if strings.HasSuffix(strings.ToLower(tmp), ".json") {
|
||||
if err = gulu.File.CopyFile(tmp, filepath.Join(tmpDir, f.Filename)); err != nil {
|
||||
} else if strings.HasSuffix(strings.ToLower(writePath), ".json") {
|
||||
if err = gulu.File.CopyFile(writePath, filepath.Join(tmpDir, f.Filename)); err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
@@ -486,8 +493,8 @@ func importConf(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(tmp)
|
||||
writePath = filepath.Join(tmpDir, entries[0].Name())
|
||||
data, err = os.ReadFile(writePath)
|
||||
if err != nil {
|
||||
logging.LogErrorf("import conf failed: %s", err)
|
||||
ret.Code = -1
|
||||
|
||||
Reference in New Issue
Block a user