mirror of
https://github.com/AlistGo/alist.git
synced 2025-04-21 20:18:47 +08:00
feat: alist v3 index permission (#2653)
* feat: alist v3 index permission * fix allowIndexed check Co-authored-by: Noah Hsu <i@nn.ci>
This commit is contained in:
parent
446f82888c
commit
62ea93837c
@ -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
|
||||
|
@ -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},
|
||||
|
@ -15,6 +15,7 @@ const (
|
||||
BasePath = "base_path"
|
||||
SiteTitle = "site_title"
|
||||
Announcement = "announcement"
|
||||
AllowIndexed = "allow_indexed"
|
||||
|
||||
Logo = "logo"
|
||||
Favicon = "favicon"
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user