From ad23d018a8fffcd80b298f396924ffaaf510f10a Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 23 Nov 2023 22:07:31 +0800 Subject: [PATCH 1/2] :arrow_up: Upgrade kernel deps --- kernel/go.mod | 6 +++--- kernel/go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index f472ace04..76f0428a9 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -50,7 +50,7 @@ require ( github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0 github.com/sashabaranov/go-openai v1.17.8 github.com/shirou/gopsutil/v3 v3.23.10 - github.com/siyuan-note/dejavu v0.0.0-20231122082037-f5d92ba84aff + github.com/siyuan-note/dejavu v0.0.0-20231123135859-866f8380004f github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20230804030110-cf250f838c80 github.com/siyuan-note/filelock v0.0.0-20231107122348-6ed75b0b525a @@ -78,7 +78,7 @@ require ( github.com/andybalholm/brotli v1.0.6 // indirect github.com/andybalholm/cascadia v1.3.2 // indirect github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect - github.com/aws/aws-sdk-go v1.48.2 // indirect + github.com/aws/aws-sdk-go v1.48.3 // indirect github.com/bytedance/sonic v1.10.2 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect @@ -96,7 +96,7 @@ require ( github.com/go-resty/resty/v2 v2.10.0 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect - github.com/golang/glog v1.1.2 // indirect + github.com/golang/glog v1.2.0 // indirect github.com/google/pprof v0.0.0-20231101202521-4ca4178f5c7a // indirect github.com/google/uuid v1.4.0 // indirect github.com/gopherjs/gopherjs v1.17.2 // indirect diff --git a/kernel/go.sum b/kernel/go.sum index 75956918f..89dd1b56a 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -49,8 +49,8 @@ github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhP github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM= github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII= -github.com/aws/aws-sdk-go v1.48.2 h1:Lf7+Y4WmHB0AQLRQZA46diSwDa+LWbwY6IGaYoCVtTc= -github.com/aws/aws-sdk-go v1.48.2/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= +github.com/aws/aws-sdk-go v1.48.3 h1:btYjT+opVFxUbRz+qSCjJe07cdX82BHmMX/FXYmoL7g= +github.com/aws/aws-sdk-go v1.48.3/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM= github.com/bytedance/sonic v1.10.2 h1:GQebETVBxYB7JGWJtLBi07OVzWwt+8dWA00gEVW2ZFE= @@ -156,8 +156,8 @@ github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14j github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= -github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= +github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= +github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= @@ -356,8 +356,8 @@ github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d h1:lvCTyBbr36+tqMccdGMwuEU+hjux/zL6xSmf5S9ITaA= github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05UtEgK5zq39gLST6uB0cf3NEHjETfB4Fgr3Gx5R9Vw= github.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8= -github.com/siyuan-note/dejavu v0.0.0-20231122082037-f5d92ba84aff h1:WpIqLLaaDskar4ZMjsevYXmIML+lbbC4PXjralFC5uI= -github.com/siyuan-note/dejavu v0.0.0-20231122082037-f5d92ba84aff/go.mod h1:qhORyWwn+RS2TMw7aga1Nkti6E0N9CjEVVw3wIgaeLQ= +github.com/siyuan-note/dejavu v0.0.0-20231123135859-866f8380004f h1:PAl/D+hLwGnHvBODNtRn9lF5eotveOLbF4DRlvbiwSg= +github.com/siyuan-note/dejavu v0.0.0-20231123135859-866f8380004f/go.mod h1:qhORyWwn+RS2TMw7aga1Nkti6E0N9CjEVVw3wIgaeLQ= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20230804030110-cf250f838c80 h1:XghjHKJd+SiL0DkGYFVC+UGUDFtnR4v9gkAbPeh9Eq8= From 9b831b967a329d8e7235754511dcca230c224dee Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 23 Nov 2023 22:10:01 +0800 Subject: [PATCH 2/2] :art: Support doc/snapshot history for database table view https://github.com/siyuan-note/siyuan/issues/9567 --- kernel/api/av.go | 40 +++++++++++++++++++++++++++++++ kernel/api/router.go | 1 + kernel/model/attribute_view.go | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/kernel/api/av.go b/kernel/api/av.go index 9ef04273f..229efe737 100644 --- a/kernel/api/av.go +++ b/kernel/api/av.go @@ -26,6 +26,46 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func renderSnapshotAttributeView(c *gin.Context) { + ret := gulu.Ret.NewResult() + defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + index := arg["snapshot"].(string) + id := arg["id"].(string) + view, attrView, err := model.RenderRepoSnapshotAttributeView(index, id) + if nil != err { + ret.Code = -1 + ret.Msg = err.Error() + return + } + + var views []map[string]interface{} + for _, v := range attrView.Views { + view := map[string]interface{}{ + "id": v.ID, + "name": v.Name, + "type": v.LayoutType, + } + + views = append(views, view) + } + + ret.Data = map[string]interface{}{ + "name": attrView.Name, + "id": attrView.ID, + "viewType": view.GetType(), + "viewID": view.GetID(), + "views": views, + "view": view, + "isMirror": av.IsMirror(attrView.ID), + } +} + func renderHistoryAttributeView(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) diff --git a/kernel/api/router.go b/kernel/api/router.go index b686f80f2..3fc9feb00 100644 --- a/kernel/api/router.go +++ b/kernel/api/router.go @@ -376,6 +376,7 @@ func ServeAPI(ginServer *gin.Engine) { ginServer.Handle("POST", "/api/av/renderAttributeView", model.CheckAuth, renderAttributeView) ginServer.Handle("POST", "/api/av/renderHistoryAttributeView", model.CheckAuth, renderHistoryAttributeView) + ginServer.Handle("POST", "/api/av/renderSnapshotAttributeView", model.CheckAuth, renderSnapshotAttributeView) ginServer.Handle("POST", "/api/av/getAttributeViewKeys", model.CheckAuth, getAttributeViewKeys) ginServer.Handle("POST", "/api/av/setAttributeViewBlockAttr", model.CheckAuth, model.CheckReadonly, setAttributeViewBlockAttr) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 658c39572..27f5a768d 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -30,6 +30,7 @@ import ( "github.com/88250/lute/ast" "github.com/88250/lute/parse" "github.com/Masterminds/sprig/v3" + "github.com/siyuan-note/dejavu/entity" "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/av" @@ -184,6 +185,49 @@ func GetBlockAttributeViewKeys(blockID string) (ret []*BlockAttributeViewKeys) { return } +func RenderRepoSnapshotAttributeView(indexID, avID string) (viewable av.Viewable, attrView *av.AttributeView, err error) { + repo, err := newRepository() + if nil != err { + return + } + + index, err := repo.GetIndex(indexID) + if nil != err { + return + } + + files, err := repo.GetFiles(index) + if nil != err { + return + } + var avFile *entity.File + for _, f := range files { + if "/storage/av/"+avID+".json" == f.Path { + avFile = f + break + } + } + + if nil == avFile { + return + } + + data, readErr := repo.OpenFile(avFile) + if nil != readErr { + logging.LogErrorf("read attribute view [%s] failed: %s", avID, readErr) + return + } + + attrView = &av.AttributeView{} + if err = gulu.JSON.UnmarshalJSON(data, attrView); nil != err { + logging.LogErrorf("unmarshal attribute view [%s] failed: %s", avID, err) + return + } + + viewable, err = renderAttributeView(attrView) + return +} + func RenderHistoryAttributeView(avID, created string) (viewable av.Viewable, attrView *av.AttributeView, err error) { createdUnix, parseErr := strconv.ParseInt(created, 10, 64) if nil != parseErr {