An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 插入资源文件时文件名长度最大限制 189 字节 https://github.com/siyuan-note/siyuan/issues/7099
Liang Ding92ca6fd339f8
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex 869e73b0a5..92e54b7719 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/7099name = util.FilterFileName(name)+ name = util.TruncateLenFileName(name)name = "net-img-" + name + "-" + ast.NewNodeID() + extwritePath := filepath.Join(assetsDirPath, name)if err = filelock.WriteFile(writePath, data); nil != err {diff --git a/kernel/util/file.go b/kernel/util/file.goindex 836a2ae2c7..ab0c360b3b 100644--- a/kernel/util/file.go+++ b/kernel/util/file.go@@ -17,12 +17,14 @@package utilimport (+ "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