add no cors config

pull/548/head
Xhofe 2021-12-25 16:44:32 +08:00
parent 91c2c21522
commit 36f07ee194
6 changed files with 23 additions and 1 deletions

View File

@ -19,6 +19,7 @@ func (driver Alist) Config() base.DriverConfig {
return base.DriverConfig{ return base.DriverConfig{
Name: "Alist", Name: "Alist",
OnlyProxy: false, OnlyProxy: false,
NoCors: true,
} }
} }

View File

@ -6,6 +6,7 @@ import (
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/http" "net/http"
"strings"
) )
type DriverConfig struct { type DriverConfig struct {
@ -14,6 +15,7 @@ type DriverConfig struct {
NoLink bool // 必须本机返回的 NoLink bool // 必须本机返回的
ApiProxy bool // 使用API中转的 ApiProxy bool // 使用API中转的
NeedSetLink bool // 需要设置链接的 NeedSetLink bool // 需要设置链接的
NoCors bool // 不可以跨域
} }
type Args struct { type Args struct {
@ -75,6 +77,16 @@ func GetDriver(name string) (driver Driver, ok bool) {
return return
} }
func GetNoCors() string {
res := make([]string, 0)
for k, v := range driversMap {
if v.Config().NoCors {
res = append(res, k)
}
}
return strings.Join(res, ",")
}
func GetDrivers() map[string][]Item { func GetDrivers() map[string][]Item {
res := make(map[string][]Item, 0) res := make(map[string][]Item, 0)
for k, v := range driversMap { for k, v := range driversMap {

View File

@ -16,6 +16,7 @@ func (driver Lanzou) Config() base.DriverConfig {
return base.DriverConfig{ return base.DriverConfig{
Name: "Lanzou", Name: "Lanzou",
NeedSetLink: true, NeedSetLink: true,
NoCors: true,
} }
} }

View File

@ -113,6 +113,7 @@ func GetAccountFiles() ([]File, error) {
files = append(files, File{ files = append(files, File{
Name: v.Name, Name: v.Name,
Size: 0, Size: 0,
Driver: v.Type,
Type: conf.FOLDER, Type: conf.FOLDER,
UpdatedAt: v.UpdatedAt, UpdatedAt: v.UpdatedAt,
}) })

View File

@ -1,6 +1,7 @@
package controllers package controllers
import ( import (
"github.com/Xhofe/alist/drivers/base"
"github.com/Xhofe/alist/model" "github.com/Xhofe/alist/model"
"github.com/Xhofe/alist/server/common" "github.com/Xhofe/alist/server/common"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -35,6 +36,12 @@ func GetSettingsPublic(c *gin.Context) {
common.ErrorResp(c, err, 400) common.ErrorResp(c, err, 400)
return return
} }
*settings = append(*settings, model.SettingItem{
Key: "no cors",
Value: base.GetNoCors(),
Description: "",
Type: "string",
})
common.SuccessResp(c, settings) common.SuccessResp(c, settings)
} }

View File

@ -19,7 +19,7 @@ func InitIndex() {
index, err = public.Public.Open("index.html") index, err = public.Public.Open("index.html")
} }
if err != nil { if err != nil {
log.Fatalf(err.Error()) //log.Fatalf(err.Error())
return return
} }
data, _ := ioutil.ReadAll(index) data, _ := ioutil.ReadAll(index)