From 2b0f2e702e44a43ab5b0f531f5415083bea31212 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 4 Jan 2025 20:44:02 +0800 Subject: [PATCH 1/5] :bug: Settings - Editor - Font is garbled on macOS https://github.com/siyuan-note/siyuan/issues/13713 --- kernel/util/font.go | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/kernel/util/font.go b/kernel/util/font.go index 97ad30b7f..0b1824ee4 100644 --- a/kernel/util/font.go +++ b/kernel/util/font.go @@ -125,20 +125,7 @@ func loadFonts() (ret []*Font) { continue } - if sfnt.PlatformLanguageID(1033) == e.LanguageID { - v, _, err := transform.Bytes(textUnicode.UTF16(textUnicode.BigEndian, textUnicode.IgnoreBOM).NewDecoder(), e.Value) - if err != nil { - //LogErrorf("decode font family [%s] failed: %s", fontPath, err) - continue - } - val := string(v) - if sfnt.NameFontFamily == e.NameID && "" != val { - family = val - } - if sfnt.NamePreferredFamily == e.NameID && "" != val { - family = val - } - } else if sfnt.PlatformLanguageID(2052) == e.LanguageID { + if sfnt.PlatformLanguageID(1033) == e.LanguageID || sfnt.PlatformLanguageID(2052) == e.LanguageID { v, _, err := transform.Bytes(textUnicode.UTF16(textUnicode.BigEndian, textUnicode.IgnoreBOM).NewDecoder(), e.Value) if err != nil { //LogErrorf("decode font family [%s] failed: %s", fontPath, err) From 4688ceabb86c9de1668a3a45001cefccb8e2d7b1 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 4 Jan 2025 21:26:30 +0800 Subject: [PATCH 2/5] :art: Improve import S3/WebDAV conf https://github.com/siyuan-note/siyuan/issues/13718 --- kernel/api/sync.go | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/kernel/api/sync.go b/kernel/api/sync.go index a2053425b..1fc70adb7 100644 --- a/kernel/api/sync.go +++ b/kernel/api/sync.go @@ -22,6 +22,7 @@ import ( "net/http" "os" "path/filepath" + "strings" "time" "github.com/siyuan-note/logging" @@ -87,10 +88,24 @@ func importSyncProviderWebDAV(c *gin.Context) { } tmpDir := filepath.Join(importDir, "webdav") - if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil { - logging.LogErrorf("import WebDAV provider failed: %s", err) + os.RemoveAll(tmpDir) + if strings.HasSuffix(strings.ToLower(tmp), ".zip") { + if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil { + logging.LogErrorf("import WebDAV provider failed: %s", err) + ret.Code = -1 + ret.Msg = err.Error() + return + } + } else if strings.HasSuffix(strings.ToLower(tmp), ".json") { + if err = gulu.File.CopyFile(tmp, filepath.Join(tmpDir, f.Filename)); err != nil { + logging.LogErrorf("import WebDAV provider failed: %s", err) + ret.Code = -1 + ret.Msg = err.Error() + } + } else { + logging.LogErrorf("invalid WebDAV provider package") ret.Code = -1 - ret.Msg = err.Error() + ret.Msg = "invalid WebDAV provider package" return } @@ -259,10 +274,24 @@ func importSyncProviderS3(c *gin.Context) { } tmpDir := filepath.Join(importDir, "s3") - if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil { - logging.LogErrorf("import S3 provider failed: %s", err) + os.RemoveAll(tmpDir) + if strings.HasSuffix(strings.ToLower(tmp), ".zip") { + if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil { + logging.LogErrorf("import S3 provider failed: %s", err) + ret.Code = -1 + ret.Msg = err.Error() + return + } + } else if strings.HasSuffix(strings.ToLower(tmp), ".json") { + if err = gulu.File.CopyFile(tmp, filepath.Join(tmpDir, f.Filename)); err != nil { + logging.LogErrorf("import S3 provider failed: %s", err) + ret.Code = -1 + ret.Msg = err.Error() + } + } else { + logging.LogErrorf("invalid S3 provider package") ret.Code = -1 - ret.Msg = err.Error() + ret.Msg = "invalid S3 provider package" return } From 9532edcab07c070cbe37e406d1f5b366ec636731 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 4 Jan 2025 21:32:09 +0800 Subject: [PATCH 3/5] :art: Improve import conf https://github.com/siyuan-note/siyuan/issues/13718 --- kernel/api/system.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kernel/api/system.go b/kernel/api/system.go index 604b3bdb7..446197fae 100644 --- a/kernel/api/system.go +++ b/kernel/api/system.go @@ -408,10 +408,24 @@ func importConf(c *gin.Context) { } tmpDir := filepath.Join(importDir, "conf") - if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil { - logging.LogErrorf("import conf failed: %s", err) + os.RemoveAll(tmpDir) + if strings.HasSuffix(strings.ToLower(tmp), ".zip") { + if err = gulu.Zip.Unzip(tmp, tmpDir); err != nil { + logging.LogErrorf("import conf failed: %s", err) + ret.Code = -1 + ret.Msg = err.Error() + return + } + } else if strings.HasSuffix(strings.ToLower(tmp), ".json") { + if err = gulu.File.CopyFile(tmp, filepath.Join(tmpDir, f.Filename)); err != nil { + logging.LogErrorf("import conf failed: %s", err) + ret.Code = -1 + ret.Msg = err.Error() + } + } else { + logging.LogErrorf("invalid conf package") ret.Code = -1 - ret.Msg = err.Error() + ret.Msg = "invalid conf package" return } From dad22713df249c3e26ca6733bc10da53670cb565 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 4 Jan 2025 22:07:27 +0800 Subject: [PATCH 4/5] :art: Generate file history when removing av entries https://github.com/siyuan-note/siyuan/issues/13717 --- kernel/model/attribute_view.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kernel/model/attribute_view.go b/kernel/model/attribute_view.go index 28015ed62..93f7fcbb6 100644 --- a/kernel/model/attribute_view.go +++ b/kernel/model/attribute_view.go @@ -2120,6 +2120,37 @@ func removeAttributeViewBlock(srcIDs []string, avID string, tx *Transaction) (er } err = av.SaveAttributeView(attrView) + + historyDir, err := GetHistoryDir(HistoryOpUpdate) + if err != nil { + logging.LogErrorf("get history dir failed: %s", err) + return + } + blockIDs := treenode.GetMirrorAttrViewBlockIDs(avID) + for _, blockID := range blockIDs { + tree := trees[blockID] + if nil == tree { + tree, _ = LoadTreeByBlockID(blockID) + } + if nil == tree { + continue + } + + historyPath := filepath.Join(historyDir, tree.Box, tree.Path) + absPath := filepath.Join(util.DataDir, tree.Box, tree.Path) + if err = filelock.Copy(absPath, historyPath); err != nil { + logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absPath, historyPath, err) + return + } + } + + srcAvPath := filepath.Join(util.DataDir, "storage", "av", avID+".json") + destAvPath := filepath.Join(historyDir, "storage", "av", avID+".json") + if copyErr := filelock.Copy(srcAvPath, destAvPath); nil != copyErr { + logging.LogErrorf("copy av [%s] failed: %s", srcAvPath, copyErr) + } + + indexHistoryDir(filepath.Base(historyDir), util.NewLute()) return } From 812068fe60093edc5cd38350784a6f5217a48caf Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 4 Jan 2025 22:07:50 +0800 Subject: [PATCH 5/5] :art: Improve indexing histories queue --- kernel/sql/queue_history.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/sql/queue_history.go b/kernel/sql/queue_history.go index 493ea9470..63a585d48 100644 --- a/kernel/sql/queue_history.go +++ b/kernel/sql/queue_history.go @@ -130,6 +130,10 @@ func DeleteOutdatedHistories(before int64) { } func IndexHistoriesQueue(histories []*History) { + if 1 > len(histories) { + return + } + historyDBQueueLock.Lock() defer historyDBQueueLock.Unlock()