mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-02 09:09:50 +08:00
🎨 桌面端支持导出图片、音频和视频 Fix https://github.com/siyuan-note/siyuan/issues/5693
This commit is contained in:
parent
5ef314e148
commit
6e754ef190
@ -16,7 +16,7 @@ export const exportAsset = (src: string) => {
|
||||
properties: ["showOverwriteConfirmation"],
|
||||
}).then((result: SaveDialogReturnValue) => {
|
||||
if (!result.canceled) {
|
||||
fetchPost("/api/file/saveAs", {src, targe: result.filePath})
|
||||
fetchPost("/api/file/copyFile", {src, dest: result.filePath})
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -34,6 +34,51 @@ import (
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func copyFile(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
src := arg["src"].(string)
|
||||
src, err := model.GetAssetAbsPath(src)
|
||||
if nil != err {
|
||||
logging.LogErrorf("get asset [%s] abs path failed: %s", src, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
|
||||
info, err := os.Stat(src)
|
||||
if nil != err {
|
||||
logging.LogErrorf("stat [%s] failed: %s", src, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
ret.Code = -1
|
||||
ret.Msg = "file is a directory"
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
|
||||
dest := arg["dest"].(string)
|
||||
if err = gulu.File.CopyFile(src, dest); nil != err {
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", src, dest, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func getFile(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
|
@ -147,6 +147,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
||||
|
||||
ginServer.Handle("POST", "/api/file/getFile", model.CheckAuth, getFile)
|
||||
ginServer.Handle("POST", "/api/file/putFile", model.CheckAuth, putFile)
|
||||
ginServer.Handle("POST", "/api/file/copyFile", model.CheckAuth, copyFile)
|
||||
|
||||
ginServer.Handle("POST", "/api/ref/refreshBacklink", model.CheckAuth, refreshBacklink)
|
||||
ginServer.Handle("POST", "/api/ref/getBacklink", model.CheckAuth, getBacklink)
|
||||
|
Loading…
Reference in New Issue
Block a user