2022-11-28 05:45:25 +00:00
|
|
|
package search
|
|
|
|
|
|
|
|
import (
|
2022-12-05 08:45:11 +00:00
|
|
|
"strings"
|
|
|
|
|
2022-11-28 05:45:25 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
|
|
|
"github.com/alist-org/alist/v3/internal/db"
|
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
|
|
|
"github.com/alist-org/alist/v3/internal/setting"
|
|
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2022-12-05 05:28:39 +00:00
|
|
|
func Progress() (*model.IndexProgress, error) {
|
2022-11-28 05:45:25 +00:00
|
|
|
p := setting.GetStr(conf.IndexProgress)
|
|
|
|
var progress model.IndexProgress
|
|
|
|
err := utils.Json.UnmarshalFromString(p, &progress)
|
|
|
|
return &progress, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func WriteProgress(progress *model.IndexProgress) {
|
|
|
|
p, err := utils.Json.MarshalToString(progress)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("marshal progress error: %+v", err)
|
|
|
|
}
|
|
|
|
err = db.SaveSettingItem(model.SettingItem{
|
|
|
|
Key: conf.IndexProgress,
|
|
|
|
Value: p,
|
|
|
|
Type: conf.TypeText,
|
|
|
|
Group: model.SINGLE,
|
|
|
|
Flag: model.PRIVATE,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("save progress error: %+v", err)
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 08:45:11 +00:00
|
|
|
|
2022-12-09 02:02:13 +00:00
|
|
|
func GetIndexPaths() []string {
|
|
|
|
indexPaths := make([]string, 0)
|
|
|
|
customIndexPaths := setting.GetStr(conf.IndexPaths)
|
|
|
|
if customIndexPaths != "" {
|
|
|
|
indexPaths = append(indexPaths, strings.Split(customIndexPaths, "\n")...)
|
|
|
|
}
|
|
|
|
return indexPaths
|
|
|
|
}
|
|
|
|
|
|
|
|
func isIndexPath(path string, indexPaths []string) bool {
|
|
|
|
for _, indexPaths := range indexPaths {
|
|
|
|
if strings.HasPrefix(path, indexPaths) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-12-05 08:45:11 +00:00
|
|
|
func GetIgnorePaths() ([]string, error) {
|
|
|
|
storages, err := db.GetEnabledStorages()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ignorePaths := make([]string, 0)
|
2022-12-06 12:43:32 +00:00
|
|
|
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
|
2022-12-05 08:45:11 +00:00
|
|
|
for _, storage := range storages {
|
|
|
|
if utils.SliceContains(skipDrivers, storage.Driver) {
|
|
|
|
// TODO: request for indexing permission
|
|
|
|
ignorePaths = append(ignorePaths, storage.MountPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
customIgnorePaths := setting.GetStr(conf.IgnorePaths)
|
|
|
|
if customIgnorePaths != "" {
|
|
|
|
ignorePaths = append(ignorePaths, strings.Split(customIgnorePaths, "\n")...)
|
|
|
|
}
|
|
|
|
return ignorePaths, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isIgnorePath(path string, ignorePaths []string) bool {
|
|
|
|
for _, ignorePath := range ignorePaths {
|
|
|
|
if strings.HasPrefix(path, ignorePath) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|