Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2025-01-04 22:31:39 +08:00
commit 32e68973ca
5 changed files with 88 additions and 23 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -130,6 +130,10 @@ func DeleteOutdatedHistories(before int64) {
}
func IndexHistoriesQueue(histories []*History) {
if 1 > len(histories) {
return
}
historyDBQueueLock.Lock()
defer historyDBQueueLock.Unlock()

View File

@ -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)