mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 Add more file formats supporting snapshots comparing https://github.com/siyuan-note/siyuan/issues/8438
This commit is contained in:
parent
e50a9b4e11
commit
30e70ade73
3 changed files with 47 additions and 2 deletions
|
|
@ -145,8 +145,20 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, upda
|
||||||
if strings.HasSuffix(file.Path, ".json") {
|
if strings.HasSuffix(file.Path, ".json") {
|
||||||
content = gulu.Str.FromBytes(data)
|
content = gulu.Str.FromBytes(data)
|
||||||
} else {
|
} else {
|
||||||
if strings.Contains(file.Path, "assets/") {
|
if strings.Contains(file.Path, "assets/") { // 剔除笔记本级或者文档级资源文件路径前缀
|
||||||
content = file.Path[strings.Index(file.Path, "assets/"):]
|
file.Path = file.Path[strings.Index(file.Path, "assets/"):]
|
||||||
|
if util.IsDisplayableAsset(file.Path) {
|
||||||
|
dir, f := filepath.Split(file.Path)
|
||||||
|
tempRepoDiffDir := filepath.Join(util.TempDir, "repo", "diff", dir)
|
||||||
|
if mkErr := os.MkdirAll(tempRepoDiffDir, 0755); nil != mkErr {
|
||||||
|
logging.LogErrorf("mkdir [%s] failed: %v", tempRepoDiffDir, mkErr)
|
||||||
|
} else {
|
||||||
|
if wrErr := os.WriteFile(filepath.Join(tempRepoDiffDir, f), data, 0644); nil != wrErr {
|
||||||
|
logging.LogErrorf("write file [%s] failed: %v", filepath.Join(tempRepoDiffDir, file.Path), wrErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
content = path.Join("repo", "diff", file.Path)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
content = file.Path
|
content = file.Path
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ func Serve(fastMode bool) {
|
||||||
servePlugins(ginServer)
|
servePlugins(ginServer)
|
||||||
serveEmojis(ginServer)
|
serveEmojis(ginServer)
|
||||||
serveTemplates(ginServer)
|
serveTemplates(ginServer)
|
||||||
|
serveRepoDiff(ginServer)
|
||||||
api.ServeAPI(ginServer)
|
api.ServeAPI(ginServer)
|
||||||
|
|
||||||
var host string
|
var host string
|
||||||
|
|
@ -349,6 +350,15 @@ func serveAssets(ginServer *gin.Engine) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func serveRepoDiff(ginServer *gin.Engine) {
|
||||||
|
ginServer.GET("/repo/diff/*path", model.CheckAuth, func(context *gin.Context) {
|
||||||
|
requestPath := context.Param("path")
|
||||||
|
p := filepath.Join(util.TempDir, "repo", "diff", requestPath)
|
||||||
|
http.ServeFile(context.Writer, context.Request, p)
|
||||||
|
return
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func serveDebug(ginServer *gin.Engine) {
|
func serveDebug(ginServer *gin.Engine) {
|
||||||
ginServer.GET("/debug/pprof/", gin.WrapF(pprof.Index))
|
ginServer.GET("/debug/pprof/", gin.WrapF(pprof.Index))
|
||||||
ginServer.GET("/debug/pprof/allocs", gin.WrapF(pprof.Index))
|
ginServer.GET("/debug/pprof/allocs", gin.WrapF(pprof.Index))
|
||||||
|
|
|
||||||
|
|
@ -193,3 +193,26 @@ func FilterSelfChildDocs(paths []string) (ret []string) {
|
||||||
func IsAssetLinkDest(dest []byte) bool {
|
func IsAssetLinkDest(dest []byte) bool {
|
||||||
return bytes.HasPrefix(dest, []byte("assets/"))
|
return bytes.HasPrefix(dest, []byte("assets/"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
SiYuanAssetsImage = []string{".apng", ".ico", ".cur", ".jpg", ".jpe", ".jpeg", ".jfif", ".pjp", ".pjpeg", ".png", ".gif", ".webp", ".bmp", ".svg", ".avif"}
|
||||||
|
SiYuanAssetsAudio = []string{".mp3", ".wav", ".ogg", ".m4a"}
|
||||||
|
SiYuanAssetsVideo = []string{".mov", ".weba", ".mkv", ".mp4", ".webm"}
|
||||||
|
)
|
||||||
|
|
||||||
|
func IsDisplayableAsset(p string) bool {
|
||||||
|
ext := strings.ToLower(filepath.Ext(p))
|
||||||
|
if "" == ext {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if gulu.Str.Contains(ext, SiYuanAssetsImage) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if gulu.Str.Contains(ext, SiYuanAssetsAudio) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if gulu.Str.Contains(ext, SiYuanAssetsVideo) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue