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"
|
"io"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(d.Addition.Address) > 0 && string(d.Addition.Address[len(d.Addition.Address)-1]) == "/" {
|
d.Addition.Address = strings.TrimSuffix(d.Addition.Address, "/")
|
||||||
d.Addition.Address = d.Addition.Address[0 : len(d.Addition.Address)-1]
|
|
||||||
}
|
|
||||||
// TODO login / refresh token
|
// TODO login / refresh token
|
||||||
//op.MustSaveDriverStorage(d)
|
//op.MustSaveDriverStorage(d)
|
||||||
return err
|
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: 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: "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: "default_page_size", Value: "30", Type: conf.TypeNumber, Group: model.SITE},
|
||||||
|
{Key: conf.AllowIndexed, Value: "false", Type: conf.TypeBool, Group: model.SITE},
|
||||||
// style settings
|
// 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.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},
|
{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"
|
BasePath = "base_path"
|
||||||
SiteTitle = "site_title"
|
SiteTitle = "site_title"
|
||||||
Announcement = "announcement"
|
Announcement = "announcement"
|
||||||
|
AllowIndexed = "allow_indexed"
|
||||||
|
|
||||||
Logo = "logo"
|
Logo = "logo"
|
||||||
Favicon = "favicon"
|
Favicon = "favicon"
|
||||||
|
@ -21,6 +21,10 @@ import (
|
|||||||
// so it should actually be a storage, just wrapped by the driver
|
// so it should actually be a storage, just wrapped by the driver
|
||||||
var storagesMap generic_sync.MapOf[string, driver.Driver]
|
var storagesMap generic_sync.MapOf[string, driver.Driver]
|
||||||
|
|
||||||
|
func GetAllStorages() []driver.Driver {
|
||||||
|
return storagesMap.Values()
|
||||||
|
}
|
||||||
|
|
||||||
func GetStorageByVirtualPath(virtualPath string) (driver.Driver, error) {
|
func GetStorageByVirtualPath(virtualPath string) (driver.Driver, error) {
|
||||||
storageDriver, ok := storagesMap.Load(virtualPath)
|
storageDriver, ok := storagesMap.Load(virtualPath)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -3,9 +3,12 @@ package search
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"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/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/db"
|
"github.com/alist-org/alist/v3/internal/db"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"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/internal/setting"
|
||||||
"github.com/alist-org/alist/v3/pkg/utils"
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
@ -54,16 +57,28 @@ func isIndexPath(path string, indexPaths []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetIgnorePaths() ([]string, error) {
|
func GetIgnorePaths() ([]string, error) {
|
||||||
storages, err := db.GetEnabledStorages()
|
storages := op.GetAllStorages()
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ignorePaths := make([]string, 0)
|
ignorePaths := make([]string, 0)
|
||||||
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
|
var skipDrivers = []string{"AList V2", "AList V3", "Virtual"}
|
||||||
|
v3Visited := make(map[string]bool)
|
||||||
for _, storage := range storages {
|
for _, storage := range storages {
|
||||||
if utils.SliceContains(skipDrivers, storage.Driver) {
|
if utils.SliceContains(skipDrivers, storage.Config().Name) {
|
||||||
// TODO: request for indexing permission
|
if storage.Config().Name == "AList V3" {
|
||||||
ignorePaths = append(ignorePaths, storage.MountPath)
|
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)
|
customIgnorePaths := setting.GetStr(conf.IgnorePaths)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user