mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-22 03:50:55 +08:00
🐛 API getFile/putFile does not perform read-write lock Fix https://github.com/siyuan-note/siyuan/issues/7832
This commit is contained in:
parent
448ad6df14
commit
fe0c7b90a3
@ -18,6 +18,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@ -26,6 +27,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
@ -104,10 +106,23 @@ func getFile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = model.ServeFile(c, filePath); nil != err {
|
data, err := filelock.ReadFile(filePath)
|
||||||
c.Status(http.StatusConflict)
|
if nil != err {
|
||||||
|
logging.LogErrorf("read file [%s] failed: %s", filePath, err)
|
||||||
|
c.Status(500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contentType := mime.TypeByExtension(filepath.Ext(filePath))
|
||||||
|
if "" == contentType {
|
||||||
|
if m := mimetype.Detect(data); nil != m {
|
||||||
|
contentType = m.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if "" == contentType {
|
||||||
|
contentType = "application/octet-stream"
|
||||||
|
}
|
||||||
|
c.Data(http.StatusOK, contentType, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func readDir(c *gin.Context) {
|
func readDir(c *gin.Context) {
|
||||||
@ -179,7 +194,7 @@ func removeFile(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.RemoveAll(filePath); nil != err {
|
if err = filelock.Remove(filePath); nil != err {
|
||||||
c.Status(500)
|
c.Status(500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ import (
|
|||||||
util2 "github.com/88250/lute/util"
|
util2 "github.com/88250/lute/util"
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/facette/natsort"
|
"github.com/facette/natsort"
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||||
@ -1641,9 +1640,3 @@ func (box *Box) removeSort(ids []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServeFile(c *gin.Context, filePath string) (err error) {
|
|
||||||
WaitForWritingFiles()
|
|
||||||
c.File(filePath)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
@ -380,6 +380,9 @@ func initMime() {
|
|||||||
mime.AddExtensionType(".dxf", "image/x-dxf")
|
mime.AddExtensionType(".dxf", "image/x-dxf")
|
||||||
mime.AddExtensionType(".dwf", "drawing/x-dwf")
|
mime.AddExtensionType(".dwf", "drawing/x-dwf")
|
||||||
mime.AddExtensionType(".pdf", "application/pdf")
|
mime.AddExtensionType(".pdf", "application/pdf")
|
||||||
|
|
||||||
|
// 文档数据文件
|
||||||
|
mime.AddExtensionType(".sy", "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
func initPandoc() {
|
func initPandoc() {
|
||||||
|
Loading…
Reference in New Issue
Block a user