diff --git a/drivers/alist_v3/driver.go b/drivers/alist_v3/driver.go index 2d0735a5..8fabd059 100644 --- a/drivers/alist_v3/driver.go +++ b/drivers/alist_v3/driver.go @@ -5,6 +5,7 @@ import ( "io" "path" "strconv" + "strings" "github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/internal/driver" @@ -32,9 +33,7 @@ func (d *AListV3) Init(ctx context.Context, storage model.Storage) error { if err != nil { return err } - if len(d.Addition.Address) > 0 && string(d.Addition.Address[len(d.Addition.Address)-1]) == "/" { - d.Addition.Address = d.Addition.Address[0 : len(d.Addition.Address)-1] - } + d.Addition.Address = strings.TrimSuffix(d.Addition.Address, "/") // TODO login / refresh token //op.MustSaveDriverStorage(d) return err diff --git a/internal/bootstrap/data/setting.go b/internal/bootstrap/data/setting.go index 3a18f2c0..db680f2d 100644 --- a/internal/bootstrap/data/setting.go +++ b/internal/bootstrap/data/setting.go @@ -78,6 +78,7 @@ func InitialSettings() []model.SettingItem { {Key: conf.Announcement, Value: "### repo\nhttps://github.com/alist-org/alist", Type: conf.TypeText, Group: model.SITE}, {Key: "pagination_type", Value: "all", Type: conf.TypeSelect, Options: "all,pagination,load_more,auto_load_more", Group: model.SITE}, {Key: "default_page_size", Value: "30", Type: conf.TypeNumber, Group: model.SITE}, + {Key: conf.AllowIndexed, Value: "false", Type: conf.TypeBool, Group: model.SITE}, // style settings {Key: conf.Logo, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeText, Group: model.STYLE}, {Key: conf.Favicon, Value: "https://cdn.jsdelivr.net/gh/alist-org/logo@main/logo.svg", Type: conf.TypeString, Group: model.STYLE}, diff --git a/internal/conf/const.go b/internal/conf/const.go index 0830ff2f..d23fbb45 100644 --- a/internal/conf/const.go +++ b/internal/conf/const.go @@ -15,6 +15,7 @@ const ( BasePath = "base_path" SiteTitle = "site_title" Announcement = "announcement" + AllowIndexed = "allow_indexed" Logo = "logo" Favicon = "favicon" diff --git a/internal/op/storage.go b/internal/op/storage.go index c01be112..b9cd7561 100644 --- a/internal/op/storage.go +++ b/internal/op/storage.go @@ -21,6 +21,10 @@ import ( // so it should actually be a storage, just wrapped by the driver var storagesMap generic_sync.MapOf[string, driver.Driver] +func GetAllStorages() []driver.Driver { + return storagesMap.Values() +} + func GetStorageByVirtualPath(virtualPath string) (driver.Driver, error) { storageDriver, ok := storagesMap.Load(virtualPath) if !ok { diff --git a/internal/search/util.go b/internal/search/util.go index c2ebd61b..883db4b3 100644 --- a/internal/search/util.go +++ b/internal/search/util.go @@ -3,9 +3,12 @@ package search import ( "strings" + "github.com/alist-org/alist/v3/drivers/alist_v3" + "github.com/alist-org/alist/v3/drivers/base" "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/op" "github.com/alist-org/alist/v3/internal/setting" "github.com/alist-org/alist/v3/pkg/utils" log "github.com/sirupsen/logrus" @@ -54,16 +57,28 @@ func isIndexPath(path string, indexPaths []string) bool { } func GetIgnorePaths() ([]string, error) { - storages, err := db.GetEnabledStorages() - if err != nil { - return nil, err - } + 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.Driver) { - // TODO: request for indexing permission - ignorePaths = append(ignorePaths, storage.MountPath) + 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 { + allowIndexed = utils.Json.Get(res.Body(), "data", conf.AllowIndexed).ToBool() + } + } + if allowIndexed { + ignorePaths = append(ignorePaths, storage.GetStorage().MountPath) + } + } else { + ignorePaths = append(ignorePaths, storage.GetStorage().MountPath) + } } } customIgnorePaths := setting.GetStr(conf.IgnorePaths)