Explorar o código

:sparkles: Support for searching asset content https://github.com/siyuan-note/siyuan/issues/8874

Daniel %!s(int64=2) %!d(string=hai) anos
pai
achega
a169b3913a
Modificáronse 2 ficheiros con 10 adicións e 2 borrados
  1. 5 2
      kernel/model/asset_content.go
  2. 5 0
      kernel/model/assets_watcher.go

+ 5 - 2
kernel/model/asset_content.go

@@ -444,9 +444,12 @@ func copyTempAsset(absPath string) (ret string) {
 		return
 	}
 
+	filelock.RWLock.Lock()
+	defer filelock.RWLock.Unlock()
+
 	ret = filepath.Join(dir, gulu.Rand.String(7)+".docx")
-	if err := filelock.Copy(absPath, ret); nil != err {
-		logging.LogErrorf("copy [%s] to [%s] failed: [%s]", absPath, ret, err)
+	if err := gulu.File.Copy(absPath, ret); nil != err {
+		logging.LogErrorf("copy [src=%s, dest=%s] failed: %s", absPath, ret, err)
 		return
 	}
 	return

+ 5 - 0
kernel/model/assets_watcher.go

@@ -73,6 +73,11 @@ func watchAssets() {
 
 				lastEvent = event
 				timer.Reset(time.Millisecond * 100)
+
+				if lastEvent.Op&fsnotify.Rename == fsnotify.Rename {
+					// 索引资源文件内容
+					IndexAssetContent(lastEvent.Name)
+				}
 			case err, ok := <-assetsWatcher.Errors:
 				if !ok {
 					return