mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-21 03:21:21 +08:00
This commit is contained in:
parent
6e9a953bf2
commit
c6b20179a6
@ -25,6 +25,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
@ -311,7 +312,6 @@ func exportAsFile(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
typ := form.Value["type"][0]
|
||||
file := form.File["file"][0]
|
||||
reader, err := file.Open()
|
||||
if nil != err {
|
||||
@ -330,5 +330,27 @@ func exportAsFile(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Data(http.StatusOK, typ, data)
|
||||
ext := filepath.Ext(file.Filename)
|
||||
name := "save-as-file-" + ast.NewNodeID() + ext
|
||||
tmpDir := filepath.Join(util.TempDir, "export")
|
||||
if err = os.MkdirAll(tmpDir, 0755); nil != err {
|
||||
logging.LogErrorf("export as file failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
tmp := filepath.Join(tmpDir, name)
|
||||
err = os.WriteFile(tmp, data, 0644)
|
||||
if nil != err {
|
||||
logging.LogErrorf("export as file failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
}
|
||||
|
||||
ret.Data = map[string]interface{}{
|
||||
"name": name,
|
||||
"file": path.Join("/export/", name),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user