Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: kernel/model/assets: refactoring (#17267)

iliya76d72e133493
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index 7b57dbc2bb..0b5d6aeefa 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -553,7 +553,7 @@ func GetAssetAbsPath(relativePath string) (string, error) {
if secondErr != nil {
return "", secondErr
}
- return "", errors.New(fmt.Sprintf(Conf.Language(12), relativePath))
+ return "", fmt.Errorf(Conf.Language(12), relativePath)
}
func getAssetAbsPath(relativePath string) (absPath string, err error) {
@@ -747,7 +747,7 @@ func uploadAssets2Cloud(assetPaths []string, bizType string, ignorePushMsg bool)
if 0 != requestResult.Code {
logging.LogErrorf("upload assets failed: %s", requestResult.Msg)
- err = errors.New(fmt.Sprintf(Conf.Language(94), requestResult.Msg))
+ err = fmt.Errorf(Conf.Language(94), requestResult.Msg)
return
}
@@ -1176,10 +1176,7 @@ func UnusedAssets(sorted bool) (ret []*UnusedItem) {
} else {
p = strings.TrimPrefix(assetAbsPath, filepath.Dir(dataAssetsAbsPath))
}
- p = filepath.ToSlash(p)
- if strings.HasPrefix(p, "/") {
- p = p[1:]
- }
+ p = strings.TrimPrefix(filepath.ToSlash(p), "/")
name := path.Base(p)
var modTime time.Time
@@ -1300,12 +1297,15 @@ func emojisInTree(tree *parse.Tree) (ret []string) {
}
if ast.NodeEmojiImg == n.Type {
tokens := n.Tokens
- idx := bytes.Index(tokens, []byte("src=\""))
- if -1 == idx {
+ _, src, found := bytes.Cut(tokens, []byte("src=\""))
+ if !found {
+ return ast.WalkContinue
+ }
+ idx := bytes.Index(src, []byte("\""))
+ if idx == -1 {
return ast.WalkContinue
}
- src := tokens[idx+len("src=\""):]
- src = src[:bytes.Index(src, []byte("\""))]
+ src = src[:idx]
ret = append(ret, string(src))
}
return ast.WalkContinue