mirror of https://github.com/Xhofe/alist
Merge f4142badff
into 4f8bc478d5
commit
3429e2383c
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -30,12 +31,21 @@ func Running() bool {
|
||||||
return Quit.Load() != nil
|
return Quit.Load() != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth int, count bool) error {
|
func BuildIndex(ctx context.Context, indexPaths []string, maxDepth int, count bool) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
objCount uint64 = 0
|
objCount uint64 = 0
|
||||||
fi model.Obj
|
fi model.Obj
|
||||||
)
|
)
|
||||||
|
ignorePaths := conf.SlicesMap[conf.IgnorePaths]
|
||||||
|
ignoreRegs := make([]*regexp.Regexp, 0, len(ignorePaths))
|
||||||
|
for _, ignorePath := range ignorePaths {
|
||||||
|
if reg, err := regexp.Compile(ignorePath); err == nil {
|
||||||
|
ignoreRegs = append(ignoreRegs, reg)
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
log.Infof("build index for: %+v", indexPaths)
|
log.Infof("build index for: %+v", indexPaths)
|
||||||
log.Infof("ignore paths: %+v", ignorePaths)
|
log.Infof("ignore paths: %+v", ignorePaths)
|
||||||
quit := make(chan struct{}, 1)
|
quit := make(chan struct{}, 1)
|
||||||
|
@ -152,8 +162,8 @@ func BuildIndex(ctx context.Context, indexPaths, ignorePaths []string, maxDepth
|
||||||
if !running.Load() {
|
if !running.Load() {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
for _, avoidPath := range ignorePaths {
|
for _, ignoreReg := range ignoreRegs {
|
||||||
if strings.HasPrefix(indexPath, avoidPath) {
|
if ignoreReg.MatchString(indexPath) {
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,9 +264,7 @@ func Update(parent string, objs []model.Obj) {
|
||||||
} else {
|
} else {
|
||||||
// build index if it's a folder
|
// build index if it's a folder
|
||||||
dir := path.Join(parent, objs[i].GetName())
|
dir := path.Join(parent, objs[i].GetName())
|
||||||
err = BuildIndex(ctx,
|
err = BuildIndex(ctx, []string{dir},
|
||||||
[]string{dir},
|
|
||||||
conf.SlicesMap[conf.IgnorePaths],
|
|
||||||
setting.GetInt(conf.MaxIndexDepth, 20)-strings.Count(dir, "/"), false)
|
setting.GetInt(conf.MaxIndexDepth, 20)-strings.Count(dir, "/"), false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("update search index error while build index: %+v", err)
|
log.Errorf("update search index error while build index: %+v", err)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package search
|
package search
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/alist_v3"
|
"github.com/alist-org/alist/v3/drivers/alist_v3"
|
||||||
|
@ -74,7 +75,7 @@ func updateIgnorePaths(customIgnorePaths string) {
|
||||||
|
|
||||||
func isIgnorePath(path string) bool {
|
func isIgnorePath(path string) bool {
|
||||||
for _, ignorePath := range conf.SlicesMap[conf.IgnorePaths] {
|
for _, ignorePath := range conf.SlicesMap[conf.IgnorePaths] {
|
||||||
if strings.HasPrefix(path, ignorePath) {
|
if match, _ := regexp.MatchString(ignorePath, path); match {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package handles
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/conf"
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
"github.com/alist-org/alist/v3/internal/search"
|
"github.com/alist-org/alist/v3/internal/search"
|
||||||
|
@ -31,7 +30,7 @@ func BuildIndex(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = search.BuildIndex(context.Background(), []string{"/"},
|
err = search.BuildIndex(context.Background(), []string{"/"},
|
||||||
conf.SlicesMap[conf.IgnorePaths], setting.GetInt(conf.MaxIndexDepth, 20), true)
|
setting.GetInt(conf.MaxIndexDepth, 20), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("build index error: %+v", err)
|
log.Errorf("build index error: %+v", err)
|
||||||
}
|
}
|
||||||
|
@ -62,8 +61,7 @@ func UpdateIndex(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := search.BuildIndex(context.Background(), req.Paths,
|
err := search.BuildIndex(context.Background(), req.Paths, req.MaxDepth, false)
|
||||||
conf.SlicesMap[conf.IgnorePaths], req.MaxDepth, false)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("update index error: %+v", err)
|
log.Errorf("update index error: %+v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue