From 33ea08dcd0b83eb8d1fa8150faf160ed003e036a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 11:40:56 +0800 Subject: [PATCH 1/3] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 7c1bab71b..ee0b6dd9a 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -462,7 +462,7 @@ func RenameAsset(oldPath, newName string) (err error) { return } - newPath := util.AssetName(newName) + filepath.Ext(oldPath) + newPath := "assets/" + util.AssetName(newName) + filepath.Ext(oldPath) if err = gulu.File.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err { util.LogErrorf("copy asset [%s] failed: %s", oldPath, err) return @@ -485,7 +485,7 @@ func RenameAsset(oldPath, newName string) (err error) { } if !bytes.Contains(data, []byte(oldPath)) { - return + continue } data = bytes.Replace(data, []byte(oldPath), []byte(newPath), -1) From 3727bd7254134e1a5a19a5c9dbc9d7444a6e37df Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 12:02:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index ee0b6dd9a..32d427e32 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -34,7 +34,6 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/88250/lute/parse" - "github.com/88250/protyle" "github.com/gabriel-vasile/mimetype" "github.com/siyuan-note/filelock" "github.com/siyuan-note/httpclient" @@ -462,13 +461,14 @@ func RenameAsset(oldPath, newName string) (err error) { return } - newPath := "assets/" + util.AssetName(newName) + filepath.Ext(oldPath) + newName = util.AssetName(newName) + filepath.Ext(oldPath) + newPath := "assets/" + newName if err = gulu.File.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err { util.LogErrorf("copy asset [%s] failed: %s", oldPath, err) return } + oldName := path.Base(oldPath) - luteEngine := NewLute() notebooks, err := ListNotebooks() if nil != err { return @@ -484,18 +484,19 @@ func RenameAsset(oldPath, newName string) (err error) { return } - if !bytes.Contains(data, []byte(oldPath)) { + if !bytes.Contains(data, []byte(oldName)) { continue } - data = bytes.Replace(data, []byte(oldPath), []byte(newPath), -1) + data = bytes.Replace(data, []byte(oldName), []byte(newName), -1) if writeErr := filelock.NoLockFileWrite(treeAbsPath, data); nil != writeErr { util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, writeErr) err = writeErr return } - tree, parseErr := protyle.ParseJSONWithoutFix(luteEngine, data) + p := filepath.ToSlash(strings.TrimPrefix(treeAbsPath, filepath.Join(util.DataDir, notebook.ID))) + tree, parseErr := LoadTree(notebook.ID, p) if nil != parseErr { util.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr) err = parseErr From 94e4226f40fe034c650786004597f981f24bccb2 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 15 Jul 2022 12:03:38 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:sparkles:=20=E8=B5=84=E6=BA=90=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E9=87=8D=E5=91=BD=E5=90=8D=20https://github.com/siyua?= =?UTF-8?q?n-note/siyuan/issues/3454?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/cache/asset.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/cache/asset.go b/kernel/cache/asset.go index c958561b5..13d5ebc55 100644 --- a/kernel/cache/asset.go +++ b/kernel/cache/asset.go @@ -60,6 +60,6 @@ func LoadAssets() { }) elapsed := time.Since(start) if 2000 < elapsed.Milliseconds() { - util.LogInfof("loaded assets [%s]", elapsed) + util.LogInfof("loaded assets [%.2fs]", elapsed.Seconds()) } }