From 76d72e133493c452dadfe00534e5b6f02499c245 Mon Sep 17 00:00:00 2001 From: iliya <68940374+12ya@users.noreply.github.com> Date: Sat, 21 Mar 2026 11:42:38 +0900 Subject: [PATCH] :recycle: kernel/model/assets: refactoring (#17267) * kernel/model/assets: refactoring * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: D <845765@qq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- kernel/model/assets.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 7b57dbc2b..0b5d6aeef 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 } - src := tokens[idx+len("src=\""):] - src = src[:bytes.Index(src, []byte("\""))] + idx := bytes.Index(src, []byte("\"")) + if idx == -1 { + return ast.WalkContinue + } + src = src[:idx] ret = append(ret, string(src)) } return ast.WalkContinue