mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 插入资源文件时文件名长度最大限制 189 字节 https://github.com/siyuan-note/siyuan/issues/7099
This commit is contained in:
parent
b3b1f3e6a5
commit
92ca6fd339
2 changed files with 19 additions and 3 deletions
|
|
@ -176,8 +176,8 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name = strings.TrimSuffix(name, ext)
|
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.FilterFileName(name)
|
||||||
|
name = util.TruncateLenFileName(name)
|
||||||
name = "net-img-" + name + "-" + ast.NewNodeID() + ext
|
name = "net-img-" + name + "-" + ast.NewNodeID() + ext
|
||||||
writePath := filepath.Join(assetsDirPath, name)
|
writePath := filepath.Join(assetsDirPath, name)
|
||||||
if err = filelock.WriteFile(writePath, data); nil != err {
|
if err = filelock.WriteFile(writePath, data); nil != err {
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,14 @@
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
"github.com/88250/lute/ast"
|
"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, "%", "")
|
ret = strings.ReplaceAll(ret, "%", "")
|
||||||
ret = strings.ReplaceAll(ret, "$", "")
|
ret = strings.ReplaceAll(ret, "$", "")
|
||||||
// 插入资源文件时文件名长度最大限制 63 个字 https://github.com/siyuan-note/siyuan/issues/7099
|
ret = TruncateLenFileName(ret)
|
||||||
ret = gulu.Str.SubStr(ret, 63)
|
|
||||||
return 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) {
|
func FilterFilePath(p string) (ret string) {
|
||||||
parts := strings.Split(p, "/")
|
parts := strings.Split(p, "/")
|
||||||
var filteredParts []string
|
var filteredParts []string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue