Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/internal/search/util.go
1560 views
1
package search
2
3
import (
4
"strings"
5
6
"github.com/alist-org/alist/v3/drivers/alist_v3"
7
"github.com/alist-org/alist/v3/drivers/base"
8
"github.com/alist-org/alist/v3/internal/conf"
9
"github.com/alist-org/alist/v3/internal/driver"
10
"github.com/alist-org/alist/v3/internal/model"
11
"github.com/alist-org/alist/v3/internal/op"
12
"github.com/alist-org/alist/v3/internal/setting"
13
"github.com/alist-org/alist/v3/pkg/utils"
14
log "github.com/sirupsen/logrus"
15
)
16
17
func Progress() (*model.IndexProgress, error) {
18
p := setting.GetStr(conf.IndexProgress)
19
var progress model.IndexProgress
20
err := utils.Json.UnmarshalFromString(p, &progress)
21
return &progress, err
22
}
23
24
func WriteProgress(progress *model.IndexProgress) {
25
p, err := utils.Json.MarshalToString(progress)
26
if err != nil {
27
log.Errorf("marshal progress error: %+v", err)
28
}
29
err = op.SaveSettingItem(&model.SettingItem{
30
Key: conf.IndexProgress,
31
Value: p,
32
Type: conf.TypeText,
33
Group: model.SINGLE,
34
Flag: model.PRIVATE,
35
})
36
if err != nil {
37
log.Errorf("save progress error: %+v", err)
38
}
39
}
40
41
func updateIgnorePaths(customIgnorePaths string) {
42
storages := op.GetAllStorages()
43
ignorePaths := make([]string, 0)
44
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
45
v3Visited := make(map[string]bool)
46
for _, storage := range storages {
47
if utils.SliceContains(skipDrivers, storage.Config().Name) {
48
if storage.Config().Name == "AList V3" {
49
addition := storage.GetAddition().(*alist_v3.Addition)
50
allowIndexed, visited := v3Visited[addition.Address]
51
if !visited {
52
url := addition.Address + "/api/public/settings"
53
res, err := base.RestyClient.R().Get(url)
54
if err == nil {
55
log.Debugf("allow_indexed body: %+v", res.String())
56
allowIndexed = utils.Json.Get(res.Body(), "data", conf.AllowIndexed).ToString() == "true"
57
v3Visited[addition.Address] = allowIndexed
58
}
59
}
60
log.Debugf("%s allow_indexed: %v", addition.Address, allowIndexed)
61
if !allowIndexed {
62
ignorePaths = append(ignorePaths, storage.GetStorage().MountPath)
63
}
64
} else {
65
ignorePaths = append(ignorePaths, storage.GetStorage().MountPath)
66
}
67
}
68
}
69
if customIgnorePaths != "" {
70
ignorePaths = append(ignorePaths, strings.Split(customIgnorePaths, "\n")...)
71
}
72
conf.SlicesMap[conf.IgnorePaths] = ignorePaths
73
}
74
75
func isIgnorePath(path string) bool {
76
for _, ignorePath := range conf.SlicesMap[conf.IgnorePaths] {
77
if strings.HasPrefix(path, ignorePath) {
78
return true
79
}
80
}
81
return false
82
}
83
84
func init() {
85
op.RegisterSettingItemHook(conf.IgnorePaths, func(item *model.SettingItem) error {
86
updateIgnorePaths(item.Value)
87
return nil
88
})
89
op.RegisterStorageHook(func(typ string, storage driver.Driver) {
90
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
91
if utils.SliceContains(skipDrivers, storage.Config().Name) {
92
updateIgnorePaths(setting.GetStr(conf.IgnorePaths))
93
}
94
})
95
}
96
97