mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 00:50:13 +01:00
🎨 Add API /api/export/exportResources to export files and folders (#8841)
This commit is contained in:
parent
9ee922794e
commit
0c7e16e558
5 changed files with 162 additions and 0 deletions
|
|
@ -23,6 +23,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
|
@ -240,6 +241,42 @@ func exportData(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
func exportResources(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
var name string
|
||||
if nil != arg["name"] {
|
||||
name = util.TruncateLenFileName(arg["name"].(string))
|
||||
}
|
||||
if name == "" {
|
||||
name = time.Now().Format("export-2006-01-02_15-04-05") // 生成的 *.zip 文件主文件名
|
||||
}
|
||||
|
||||
var resourcePaths []string // 文件/文件夹在工作空间中的路径
|
||||
if nil != arg["paths"] {
|
||||
for _, resourcePath := range arg["paths"].([]interface{}) {
|
||||
resourcePaths = append(resourcePaths, resourcePath.(string))
|
||||
}
|
||||
}
|
||||
|
||||
zipFilePath, err := model.ExportResources(resourcePaths, name)
|
||||
if nil != err {
|
||||
ret.Code = 1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 7000}
|
||||
return
|
||||
}
|
||||
ret.Data = map[string]interface{}{
|
||||
"path": zipFilePath, // 相对于工作空间目录的路径
|
||||
}
|
||||
}
|
||||
|
||||
func batchExportMd(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue