From 84b0cf70335e15150eeca4f4cc6ba160ee9a9a64 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Tue, 30 Aug 2022 20:12:26 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=95=B0=E6=8D=AE=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E6=96=87=E6=A1=A3=E4=B8=AD=E6=94=AF=E6=8C=81=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E8=BF=87=E6=BB=A4=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/5754?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/history.go | 19 ++++++++++++++----- kernel/server/serve.go | 7 ++----- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/kernel/model/history.go b/kernel/model/history.go index 6c2434795..4e5f8f16a 100644 --- a/kernel/model/history.go +++ b/kernel/model/history.go @@ -606,20 +606,29 @@ func fromSQLHistories(sqlHistories []*sql.History) (ret []*History) { tmpTime = unixSec } if tmpTime == unixSec { - items = append(items, &HistoryItem{ + item := &HistoryItem{ Title: sqlHistory.Title, Path: filepath.Join(util.HistoryDir, sqlHistory.Path), - }) + } + if HistoryTypeAsset == sqlHistory.Type { + item.Path = filepath.ToSlash(strings.TrimPrefix(item.Path, util.WorkspaceDir)) + } + items = append(items, item) } else { ret = append(ret, &History{ HCreated: time.Unix(unixSec, 0).Format("2006-01-02 15:04:05"), Items: items, }) - items = []*HistoryItem{} - items = append(items, &HistoryItem{ + + item := &HistoryItem{ Title: sqlHistory.Title, Path: filepath.Join(util.HistoryDir, sqlHistory.Path), - }) + } + if HistoryTypeAsset == sqlHistory.Type { + item.Path = filepath.ToSlash(strings.TrimPrefix(item.Path, util.WorkspaceDir)) + } + items = []*HistoryItem{} + items = append(items, item) } } if 0 < len(items) { diff --git a/kernel/server/serve.go b/kernel/server/serve.go index a974d91a1..993780bf4 100644 --- a/kernel/server/serve.go +++ b/kernel/server/serve.go @@ -204,11 +204,8 @@ func serveAssets(ginServer *gin.Engine) { http.ServeFile(context.Writer, context.Request, p) return }) - ginServer.GET("/history/:dir/assets/*name", model.CheckAuth, func(context *gin.Context) { - dir := context.Param("dir") - name := context.Param("name") - relativePath := path.Join(dir, "assets", name) - p := filepath.Join(util.HistoryDir, relativePath) + ginServer.GET("/history/*path", model.CheckAuth, func(context *gin.Context) { + p := filepath.Join(util.HistoryDir, context.Param("path")) http.ServeFile(context.Writer, context.Request, p) return })