mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-23 10:00:13 +01:00
⬆️ 数据仓库迁出时忽略 .tmp 临时文件 https://github.com/siyuan-note/siyuan/issues/7087
This commit is contained in:
parent
928942951b
commit
15cd499f56
1 changed files with 52 additions and 23 deletions
|
|
@ -105,11 +105,19 @@ func AutoOCRAssets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
autoOCRAssets()
|
||||||
|
|
||||||
|
time.Sleep(7 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func autoOCRAssets() {
|
||||||
|
defer logging.Recover()
|
||||||
|
|
||||||
assetsPath := GetDataAssetsAbsPath()
|
assetsPath := GetDataAssetsAbsPath()
|
||||||
assets := getUnOCRAssetsAbsPaths()
|
assets := getUnOCRAssetsAbsPaths()
|
||||||
|
|
||||||
waitGroup := &sync.WaitGroup{}
|
waitGroup := &sync.WaitGroup{}
|
||||||
lock := &sync.Mutex{}
|
|
||||||
p, _ := ants.NewPoolWithFunc(4, func(arg interface{}) {
|
p, _ := ants.NewPoolWithFunc(4, func(arg interface{}) {
|
||||||
defer waitGroup.Done()
|
defer waitGroup.Done()
|
||||||
|
|
||||||
|
|
@ -117,9 +125,9 @@ func AutoOCRAssets() {
|
||||||
text := Tesseract(assetAbsPath)
|
text := Tesseract(assetAbsPath)
|
||||||
p := strings.TrimPrefix(assetAbsPath, assetsPath)
|
p := strings.TrimPrefix(assetAbsPath, assetsPath)
|
||||||
p = "assets" + filepath.ToSlash(p)
|
p = "assets" + filepath.ToSlash(p)
|
||||||
lock.Lock()
|
assetsTextsLock.Lock()
|
||||||
assetsTexts[p] = text
|
assetsTexts[p] = text
|
||||||
lock.Unlock()
|
assetsTextsLock.Unlock()
|
||||||
assetsTextsChanged = true
|
assetsTextsChanged = true
|
||||||
})
|
})
|
||||||
for _, assetAbsPath := range assets {
|
for _, assetAbsPath := range assets {
|
||||||
|
|
@ -129,8 +137,29 @@ func AutoOCRAssets() {
|
||||||
waitGroup.Wait()
|
waitGroup.Wait()
|
||||||
p.Release()
|
p.Release()
|
||||||
|
|
||||||
time.Sleep(7 * time.Second)
|
cleanNotFoundAssetsTexts()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cleanNotFoundAssetsTexts() {
|
||||||
|
tmp := assetsTexts
|
||||||
|
|
||||||
|
assetsPath := GetDataAssetsAbsPath()
|
||||||
|
var toRemoves []string
|
||||||
|
for asset, _ := range tmp {
|
||||||
|
assetAbsPath := strings.TrimPrefix(asset, "assets")
|
||||||
|
assetAbsPath = filepath.Join(assetsPath, assetAbsPath)
|
||||||
|
if !gulu.File.IsExist(assetAbsPath) {
|
||||||
|
toRemoves = append(toRemoves, asset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assetsTextsLock.Lock()
|
||||||
|
for _, asset := range toRemoves {
|
||||||
|
delete(assetsTexts, asset)
|
||||||
|
assetsTextsChanged = true
|
||||||
|
}
|
||||||
|
assetsTextsLock.Unlock()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUnOCRAssetsAbsPaths() (ret []string) {
|
func getUnOCRAssetsAbsPaths() (ret []string) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue