From 92ca6fd339f84dccd8617dd3a7a586d2e0d0908f Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 20 Jan 2023 11:27:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?:art:=20=E6=8F=92=E5=85=A5=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=96=87=E4=BB=B6=E6=97=B6=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E6=9C=80=E5=A4=A7=E9=99=90=E5=88=B6=20189=20?= =?UTF-8?q?=E5=AD=97=E8=8A=82=20https://github.com/siyuan-note/siyuan/issu?= =?UTF-8?q?es/7099?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/assets.go | 2 +- kernel/util/file.go | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 869e73b0a..92e54b771 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -176,8 +176,8 @@ func NetImg2LocalAssets(rootID string) (err error) { } } name = strings.TrimSuffix(name, ext) - name = gulu.Str.SubStr(name, 63) // 插入资源文件时文件名长度最大限制 63 个字 https://github.com/siyuan-note/siyuan/issues/7099 name = util.FilterFileName(name) + name = util.TruncateLenFileName(name) name = "net-img-" + name + "-" + ast.NewNodeID() + ext writePath := filepath.Join(assetsDirPath, name) if err = filelock.WriteFile(writePath, data); nil != err { diff --git a/kernel/util/file.go b/kernel/util/file.go index 836a2ae2c..ab0c360b3 100644 --- a/kernel/util/file.go +++ b/kernel/util/file.go @@ -17,12 +17,14 @@ package util import ( + "bytes" "io" "os" "path" "path/filepath" "sort" "strings" + "unicode/utf8" "github.com/88250/gulu" "github.com/88250/lute/ast" @@ -141,11 +143,25 @@ func FilterUploadFileName(name string) string { ret = strings.ReplaceAll(ret, "#", "") ret = strings.ReplaceAll(ret, "%", "") ret = strings.ReplaceAll(ret, "$", "") - // 插入资源文件时文件名长度最大限制 63 个字 https://github.com/siyuan-note/siyuan/issues/7099 - ret = gulu.Str.SubStr(ret, 63) + ret = TruncateLenFileName(ret) return ret } +func TruncateLenFileName(name string) (ret string) { + // 插入资源文件时文件名长度最大限制 189 字节 https://github.com/siyuan-note/siyuan/issues/7099 + var byteCount int + buf := bytes.Buffer{} + for _, r := range name { + byteCount += utf8.RuneLen(r) + if 189 < byteCount { + break + } + buf.WriteRune(r) + } + ret = buf.String() + return +} + func FilterFilePath(p string) (ret string) { parts := strings.Split(p, "/") var filteredParts []string From 61c57c9c30bef716c28de0eefb8dc60a1f966c2a Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Fri, 20 Jan 2023 11:49:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?:art:=20Android=20=E7=AB=AF=E5=89=8D?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E5=88=87=E6=8D=A2=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=A7=A6=E5=8F=91=E5=90=8C=E6=AD=A5=20=20https://github.com/si?= =?UTF-8?q?yuan-note/siyuan/issues/7122?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/sync.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/kernel/api/sync.go b/kernel/api/sync.go index 1e3a644fd..4b04c6cce 100644 --- a/kernel/api/sync.go +++ b/kernel/api/sync.go @@ -40,6 +40,23 @@ func getBootSync(c *gin.Context) { func performSync(c *gin.Context) { ret := gulu.Ret.NewResult() defer c.JSON(http.StatusOK, ret) + + arg, ok := util.JsonArg(c, ret) + if !ok { + return + } + + // Android 端前后台切换时自动触发同步 https://github.com/siyuan-note/siyuan/issues/7122 + var mobileSwitch bool + if mobileSwitchArg := arg["mobileSwitch"]; nil != mobileSwitchArg { + mobileSwitch = mobileSwitchArg.(bool) + } + if mobileSwitch { + if nil == model.Conf.User || !model.Conf.Sync.Enabled { + return + } + } + model.SyncData(false, false, true) }