Skip to content

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

:recycle: kernel/model/assets: refactor with strings.Cut (#17266)

iliya7c727bd14096
diff --git a/kernel/model/assets.go b/kernel/model/assets.go
index 5d9e2dfb6d..7b57dbc2bb 100644
--- a/kernel/model/assets.go
+++ b/kernel/model/assets.go
@@ -138,11 +138,11 @@ func HandleAssetsChangeEvent(assetAbsPath string) {
func removeAssetThumbnail(assetAbsPath string) {
if util.IsCompressibleAssetImage(assetAbsPath) {
p := filepath.ToSlash(assetAbsPath)
- idx := strings.Index(p, "assets/")
- if -1 == idx {
+ _, after, found := strings.Cut(p, "assets/")
+ if !found {
return
}
- thumbnailPath := filepath.Join(util.TempDir, "thumbnails", "assets", p[idx+7:])
+ thumbnailPath := filepath.Join(util.TempDir, "thumbnails", "assets", after)
os.RemoveAll(thumbnailPath)
}
}