Files
OpenList/internal/search/util.go
Kuingsmile fdcc2f136e chore: change module name to OpenListTeam/OpenList (#2)
* Enable blank issue

* chore(README.md): update docs (temporally)

* Update FUNDING.yml

* chore: purge README.md

* chore: change module name to OpenListTeam/OpenList

* fix: fix link errors

* chore: remove v3 in module name

* fix: resolve some conficts

* fix: resolve conficts

* docs: update with latest file

---------

Co-authored-by: ShenLin <773933146@qq.com>
Co-authored-by: Hantong Chen <cxwdyx620@gmail.com>
Co-authored-by: joshua <i@joshua.su>
Co-authored-by: Hantong Chen <70561268+cxw620@users.noreply.github.com>
2025-06-12 22:02:46 +08:00

96 lines
2.9 KiB
Go

package search
import (
"strings"
"github.com/OpenListTeam/OpenList/drivers/alist_v3"
"github.com/OpenListTeam/OpenList/drivers/base"
"github.com/OpenListTeam/OpenList/internal/conf"
"github.com/OpenListTeam/OpenList/internal/driver"
"github.com/OpenListTeam/OpenList/internal/model"
"github.com/OpenListTeam/OpenList/internal/op"
"github.com/OpenListTeam/OpenList/internal/setting"
"github.com/OpenListTeam/OpenList/pkg/utils"
log "github.com/sirupsen/logrus"
)
func Progress() (*model.IndexProgress, error) {
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 = op.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)
}
}
func updateIgnorePaths(customIgnorePaths string) {
storages := op.GetAllStorages()
ignorePaths := make([]string, 0)
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
v3Visited := make(map[string]bool)
for _, storage := range storages {
if utils.SliceContains(skipDrivers, storage.Config().Name) {
if storage.Config().Name == "AList V3" {
addition := storage.GetAddition().(*alist_v3.Addition)
allowIndexed, visited := v3Visited[addition.Address]
if !visited {
url := addition.Address + "/api/public/settings"
res, err := base.RestyClient.R().Get(url)
if err == nil {
log.Debugf("allow_indexed body: %+v", res.String())
allowIndexed = utils.Json.Get(res.Body(), "data", conf.AllowIndexed).ToString() == "true"
v3Visited[addition.Address] = allowIndexed
}
}
log.Debugf("%s allow_indexed: %v", addition.Address, allowIndexed)
if !allowIndexed {
ignorePaths = append(ignorePaths, storage.GetStorage().MountPath)
}
} else {
ignorePaths = append(ignorePaths, storage.GetStorage().MountPath)
}
}
}
if customIgnorePaths != "" {
ignorePaths = append(ignorePaths, strings.Split(customIgnorePaths, "\n")...)
}
conf.SlicesMap[conf.IgnorePaths] = ignorePaths
}
func isIgnorePath(path string) bool {
for _, ignorePath := range conf.SlicesMap[conf.IgnorePaths] {
if strings.HasPrefix(path, ignorePath) {
return true
}
}
return false
}
func init() {
op.RegisterSettingItemHook(conf.IgnorePaths, func(item *model.SettingItem) error {
updateIgnorePaths(item.Value)
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(setting.GetStr(conf.IgnorePaths))
}
})
}