mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
⚡ Improve the image loading performance in the database https://github.com/siyuan-note/siyuan/issues/15245
This commit is contained in:
parent
9bb91c3a97
commit
c852f6f51a
8 changed files with 113 additions and 8 deletions
|
|
@ -491,9 +491,17 @@ func serveAssets(ginServer *gin.Engine) {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
if serveThumbnail(context, p, requestPath) {
|
||||
// 如果请求缩略图服务成功则返回
|
||||
return
|
||||
}
|
||||
|
||||
// 返回原始文件
|
||||
http.ServeFile(context.Writer, context.Request, p)
|
||||
return
|
||||
})
|
||||
|
||||
ginServer.GET("/history/*path", model.CheckAuth, model.CheckAdminRole, func(context *gin.Context) {
|
||||
p := filepath.Join(util.HistoryDir, context.Param("path"))
|
||||
http.ServeFile(context.Writer, context.Request, p)
|
||||
|
|
@ -501,6 +509,24 @@ func serveAssets(ginServer *gin.Engine) {
|
|||
})
|
||||
}
|
||||
|
||||
func serveThumbnail(context *gin.Context, assetAbsPath, requestPath string) bool {
|
||||
if style := context.Query("style"); style == "thumb" && model.NeedGenerateAssetsThumbnail(assetAbsPath) { // 请求缩略图
|
||||
thumbnailPath := filepath.Join(util.TempDir, "thumbnails", "assets", requestPath)
|
||||
if !gulu.File.IsExist(thumbnailPath) {
|
||||
// 如果缩略图不存在,则生成缩略图
|
||||
err := model.GenerateAssetsThumbnail(assetAbsPath, thumbnailPath)
|
||||
if err != nil {
|
||||
logging.LogErrorf("generate thumbnail failed: %s", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
http.ServeFile(context.Writer, context.Request, thumbnailPath)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func serveRepoDiff(ginServer *gin.Engine) {
|
||||
ginServer.GET("/repo/diff/*path", model.CheckAuth, model.CheckAdminRole, func(context *gin.Context) {
|
||||
requestPath := context.Param("path")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue