mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-17 12:38:07 +01:00
🎨 Support copying file in the asset menu on Windows and macOS (#17049)
This commit is contained in:
parent
d484ddc079
commit
ca41244188
24 changed files with 387 additions and 2 deletions
|
|
@ -17,17 +17,20 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/88250/clipboard"
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func readFilePaths(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(200, ret)
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
var paths []string
|
||||
if !gulu.OS.IsLinux() { // Linux 端不再支持 `粘贴为纯文本` 时处理文件绝对路径 https://github.com/siyuan-note/siyuan/issues/5825
|
||||
|
|
@ -52,3 +55,37 @@ func readFilePaths(c *gin.Context) {
|
|||
}
|
||||
ret.Data = data
|
||||
}
|
||||
|
||||
func writeFilePath(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
pathArg, ok := arg["path"].(string)
|
||||
if !ok || pathArg == "" {
|
||||
ret.Code = -1
|
||||
ret.Msg = "path is required"
|
||||
return
|
||||
}
|
||||
|
||||
absPath, err := model.GetAssetAbsPath(pathArg)
|
||||
if err != nil {
|
||||
logging.LogErrorf("get asset [%s] abs path failed: %s", pathArg, err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
|
||||
if err = util.WriteFilePaths([]string{absPath}); err != nil {
|
||||
logging.LogErrorf("write file path to clipboard failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
ret.Data = map[string]interface{}{"closeTimeout": 5000}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,6 +297,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/extension/copy", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, extensionCopy)
|
||||
|
||||
ginServer.Handle("POST", "/api/clipboard/readFilePaths", model.CheckAuth, model.CheckAdminRole, readFilePaths)
|
||||
ginServer.Handle("POST", "/api/clipboard/writeFilePath", model.CheckAuth, model.CheckAdminRole, writeFilePath)
|
||||
|
||||
ginServer.Handle("POST", "/api/asset/uploadCloud", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, uploadCloud)
|
||||
ginServer.Handle("POST", "/api/asset/uploadCloudByAssetsPaths", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, uploadCloudByAssetsPaths)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue