2022-11-28 05:45:25 +00:00
|
|
|
package search
|
|
|
|
|
|
|
|
import (
|
2022-12-05 08:45:11 +00:00
|
|
|
"strings"
|
|
|
|
|
2022-12-10 11:03:09 +00:00
|
|
|
"github.com/alist-org/alist/v3/drivers/alist_v3"
|
|
|
|
"github.com/alist-org/alist/v3/drivers/base"
|
2022-11-28 05:45:25 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
2022-12-24 12:23:04 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/driver"
|
2022-11-28 05:45:25 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-12-10 11:03:09 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/op"
|
2022-11-28 05:45:25 +00:00
|
|
|
"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)
|
|
|
|
}
|
2022-12-18 11:51:20 +00:00
|
|
|
err = op.SaveSettingItem(&model.SettingItem{
|
2022-11-28 05:45:25 +00:00
|
|
|
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-24 12:23:04 +00:00
|
|
|
func updateIgnorePaths() {
|
2022-12-10 11:03:09 +00:00
|
|
|
storages := op.GetAllStorages()
|
2022-12-05 08:45:11 +00:00
|
|
|
ignorePaths := make([]string, 0)
|
2022-12-06 12:43:32 +00:00
|
|
|
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
|
2022-12-10 11:03:09 +00:00
|
|
|
v3Visited := make(map[string]bool)
|
2022-12-05 08:45:11 +00:00
|
|
|
for _, storage := range storages {
|
2022-12-10 11:03:09 +00:00
|
|
|
if utils.SliceContains(skipDrivers, storage.Config().Name) {
|
|
|
|
if storage.Config().Name == "AList V3" {
|
2022-12-13 10:03:30 +00:00
|
|
|
addition := storage.GetAddition().(*alist_v3.Addition)
|
2022-12-10 11:03:09 +00:00
|
|
|
allowIndexed, visited := v3Visited[addition.Address]
|
|
|
|
if !visited {
|
|
|
|
url := addition.Address + "/api/public/settings"
|
|
|
|
res, err := base.RestyClient.R().Get(url)
|
|
|
|
if err == nil {
|
2023-02-07 07:14:39 +00:00
|
|
|
log.Debugf("allow_indexed body: %+v", res.String())
|
|
|
|
allowIndexed = utils.Json.Get(res.Body(), "data", conf.AllowIndexed).ToString() == "true"
|
2023-01-19 09:00:49 +00:00
|
|
|
v3Visited[addition.Address] = allowIndexed
|
2022-12-10 11:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-07 07:14:39 +00:00
|
|
|
log.Debugf("%s allow_indexed: %v", addition.Address, allowIndexed)
|
2023-01-19 09:00:49 +00:00
|
|
|
if !allowIndexed {
|
2022-12-10 11:03:09 +00:00
|
|
|
ignorePaths = append(ignorePaths, storage.GetStorage().MountPath)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ignorePaths = append(ignorePaths, storage.GetStorage().MountPath)
|
|
|
|
}
|
2022-12-05 08:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
customIgnorePaths := setting.GetStr(conf.IgnorePaths)
|
|
|
|
if customIgnorePaths != "" {
|
|
|
|
ignorePaths = append(ignorePaths, strings.Split(customIgnorePaths, "\n")...)
|
|
|
|
}
|
2022-12-24 12:23:04 +00:00
|
|
|
conf.SlicesMap[conf.IgnorePaths] = ignorePaths
|
2022-12-05 08:45:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-24 12:23:04 +00:00
|
|
|
func isIgnorePath(path string) bool {
|
|
|
|
for _, ignorePath := range conf.SlicesMap[conf.IgnorePaths] {
|
2022-12-05 08:45:11 +00:00
|
|
|
if strings.HasPrefix(path, ignorePath) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2022-12-24 12:23:04 +00:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
op.RegisterSettingItemHook(conf.IgnorePaths, func(item *model.SettingItem) error {
|
|
|
|
updateIgnorePaths()
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
op.RegisterStorageHook(func(typ string, storage driver.Driver) {
|
|
|
|
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
|
|
|
|
if utils.SliceContains(skipDrivers, storage.Config().Name) {
|
|
|
|
updateIgnorePaths()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|