mirror of https://github.com/Xhofe/alist
* clean referer when use proxy * feat: customize proxy ignore headers Co-authored-by: Noah Hsu <i@nn.ci>pull/2771/head
parent
372030071e
commit
146619134d
|
@ -97,6 +97,7 @@ func InitialSettings() []model.SettingItem {
|
||||||
{Key: conf.ImageTypes, Value: "jpg,tiff,jpeg,png,gif,bmp,svg,ico,swf,webp", Type: conf.TypeText, Group: model.PREVIEW, Flag: model.PRIVATE},
|
{Key: conf.ImageTypes, Value: "jpg,tiff,jpeg,png,gif,bmp,svg,ico,swf,webp", Type: conf.TypeText, Group: model.PREVIEW, Flag: model.PRIVATE},
|
||||||
//{Key: conf.OfficeTypes, Value: "doc,docx,xls,xlsx,ppt,pptx", Type: conf.TypeText, Group: model.PREVIEW, Flag: model.PRIVATE},
|
//{Key: conf.OfficeTypes, Value: "doc,docx,xls,xlsx,ppt,pptx", Type: conf.TypeText, Group: model.PREVIEW, Flag: model.PRIVATE},
|
||||||
{Key: conf.ProxyTypes, Value: "m3u8", Type: conf.TypeText, Group: model.PREVIEW, Flag: model.PRIVATE},
|
{Key: conf.ProxyTypes, Value: "m3u8", Type: conf.TypeText, Group: model.PREVIEW, Flag: model.PRIVATE},
|
||||||
|
{Key: conf.ProxyIgnoreHeaders, Value: "authorization,referer", Type: conf.TypeText, Group: model.PRIVATE, Flag: model.PRIVATE},
|
||||||
{Key: "external_previews", Value: `{}`, Type: conf.TypeText, Group: model.PREVIEW},
|
{Key: "external_previews", Value: `{}`, Type: conf.TypeText, Group: model.PREVIEW},
|
||||||
{Key: "iframe_previews", Value: `{
|
{Key: "iframe_previews", Value: `{
|
||||||
"doc,docx,xls,xlsx,ppt,pptx": {
|
"doc,docx,xls,xlsx,ppt,pptx": {
|
||||||
|
|
|
@ -15,23 +15,21 @@ const (
|
||||||
BasePath = "base_path"
|
BasePath = "base_path"
|
||||||
SiteTitle = "site_title"
|
SiteTitle = "site_title"
|
||||||
Announcement = "announcement"
|
Announcement = "announcement"
|
||||||
AllowIndexed = "allow_indexed"
|
AllowIndexed = "allow_indexed"
|
||||||
|
|
||||||
Logo = "logo"
|
Logo = "logo"
|
||||||
Favicon = "favicon"
|
Favicon = "favicon"
|
||||||
MainColor = "main_color"
|
MainColor = "main_color"
|
||||||
|
|
||||||
// preview
|
// preview
|
||||||
TextTypes = "text_types"
|
TextTypes = "text_types"
|
||||||
AudioTypes = "audio_types"
|
AudioTypes = "audio_types"
|
||||||
VideoTypes = "video_types"
|
VideoTypes = "video_types"
|
||||||
ImageTypes = "image_types"
|
ImageTypes = "image_types"
|
||||||
// OfficeTypes = "office_types"
|
ProxyTypes = "proxy_types"
|
||||||
ProxyTypes = "proxy_types"
|
ProxyIgnoreHeaders = "proxy_ignore_headers"
|
||||||
OfficeViewers = "office_viewers"
|
AudioAutoplay = "audio_autoplay"
|
||||||
PdfViewers = "pdf_viewers"
|
VideoAutoplay = "video_autoplay"
|
||||||
AudioAutoplay = "audio_autoplay"
|
|
||||||
VideoAutoplay = "video_autoplay"
|
|
||||||
|
|
||||||
// global
|
// global
|
||||||
HideFiles = "hide_files"
|
HideFiles = "hide_files"
|
||||||
|
|
|
@ -15,7 +15,7 @@ var (
|
||||||
Conf *Config
|
Conf *Config
|
||||||
)
|
)
|
||||||
|
|
||||||
var TypesMap = make(map[string][]string)
|
var SlicesMap = make(map[string][]string)
|
||||||
var FilenameCharMap = make(map[string]string)
|
var FilenameCharMap = make(map[string]string)
|
||||||
var PrivacyReg []*regexp.Regexp
|
var PrivacyReg []*regexp.Regexp
|
||||||
|
|
||||||
|
|
|
@ -33,26 +33,29 @@ type SettingItemHook func(item *model.SettingItem) error
|
||||||
|
|
||||||
var settingItemHooks = map[string]SettingItemHook{
|
var settingItemHooks = map[string]SettingItemHook{
|
||||||
conf.VideoTypes: func(item *model.SettingItem) error {
|
conf.VideoTypes: func(item *model.SettingItem) error {
|
||||||
conf.TypesMap[conf.VideoTypes] = strings.Split(item.Value, ",")
|
conf.SlicesMap[conf.VideoTypes] = strings.Split(item.Value, ",")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
conf.AudioTypes: func(item *model.SettingItem) error {
|
conf.AudioTypes: func(item *model.SettingItem) error {
|
||||||
conf.TypesMap[conf.AudioTypes] = strings.Split(item.Value, ",")
|
conf.SlicesMap[conf.AudioTypes] = strings.Split(item.Value, ",")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
conf.ImageTypes: func(item *model.SettingItem) error {
|
conf.ImageTypes: func(item *model.SettingItem) error {
|
||||||
conf.TypesMap[conf.ImageTypes] = strings.Split(item.Value, ",")
|
conf.SlicesMap[conf.ImageTypes] = strings.Split(item.Value, ",")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
conf.TextTypes: func(item *model.SettingItem) error {
|
conf.TextTypes: func(item *model.SettingItem) error {
|
||||||
conf.TypesMap[conf.TextTypes] = strings.Split(item.Value, ",")
|
conf.SlicesMap[conf.TextTypes] = strings.Split(item.Value, ",")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
conf.ProxyTypes: func(item *model.SettingItem) error {
|
conf.ProxyTypes: func(item *model.SettingItem) error {
|
||||||
conf.TypesMap[conf.ProxyTypes] = strings.Split(item.Value, ",")
|
conf.SlicesMap[conf.ProxyTypes] = strings.Split(item.Value, ",")
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
conf.ProxyIgnoreHeaders: func(item *model.SettingItem) error {
|
||||||
|
conf.SlicesMap[conf.ProxyIgnoreHeaders] = strings.Split(item.Value, ",")
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
||||||
conf.PrivacyRegs: func(item *model.SettingItem) error {
|
conf.PrivacyRegs: func(item *model.SettingItem) error {
|
||||||
regStrs := strings.Split(item.Value, "\n")
|
regStrs := strings.Split(item.Value, "\n")
|
||||||
regs := make([]*regexp.Regexp, 0, len(regStrs))
|
regs := make([]*regexp.Regexp, 0, len(regStrs))
|
||||||
|
|
|
@ -119,19 +119,16 @@ func CreateTempFile(r io.ReadCloser) (*os.File, error) {
|
||||||
// GetFileType get file type
|
// GetFileType get file type
|
||||||
func GetFileType(filename string) int {
|
func GetFileType(filename string) int {
|
||||||
ext := strings.ToLower(Ext(filename))
|
ext := strings.ToLower(Ext(filename))
|
||||||
//if SliceContains(conf.TypesMap[conf.OfficeTypes], ext) {
|
if SliceContains(conf.SlicesMap[conf.AudioTypes], ext) {
|
||||||
// return conf.OFFICE
|
|
||||||
//}
|
|
||||||
if SliceContains(conf.TypesMap[conf.AudioTypes], ext) {
|
|
||||||
return conf.AUDIO
|
return conf.AUDIO
|
||||||
}
|
}
|
||||||
if SliceContains(conf.TypesMap[conf.VideoTypes], ext) {
|
if SliceContains(conf.SlicesMap[conf.VideoTypes], ext) {
|
||||||
return conf.VIDEO
|
return conf.VIDEO
|
||||||
}
|
}
|
||||||
if SliceContains(conf.TypesMap[conf.ImageTypes], ext) {
|
if SliceContains(conf.SlicesMap[conf.ImageTypes], ext) {
|
||||||
return conf.IMAGE
|
return conf.IMAGE
|
||||||
}
|
}
|
||||||
if SliceContains(conf.TypesMap[conf.TextTypes], ext) {
|
if SliceContains(conf.SlicesMap[conf.TextTypes], ext) {
|
||||||
return conf.TEXT
|
return conf.TEXT
|
||||||
}
|
}
|
||||||
return conf.UNKNOWN
|
return conf.UNKNOWN
|
||||||
|
|
|
@ -10,7 +10,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/alist-org/alist/v3/internal/conf"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
"github.com/alist-org/alist/v3/pkg/utils"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
@ -67,7 +69,7 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for h, val := range r.Header {
|
for h, val := range r.Header {
|
||||||
if strings.ToLower(h) == "authorization" {
|
if utils.SliceContains(conf.SlicesMap[conf.ProxyIgnoreHeaders], strings.ToLower(h)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
req.Header[h] = val
|
req.Header[h] = val
|
||||||
|
|
|
@ -91,7 +91,7 @@ func shouldProxy(storage driver.Driver, filename string) bool {
|
||||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if utils.SliceContains(conf.TypesMap[conf.ProxyTypes], utils.Ext(filename)) {
|
if utils.SliceContains(conf.SlicesMap[conf.ProxyTypes], utils.Ext(filename)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -108,10 +108,10 @@ func canProxy(storage driver.Driver, filename string) bool {
|
||||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy || storage.GetStorage().WebdavProxy() {
|
if storage.Config().MustProxy() || storage.GetStorage().WebProxy || storage.GetStorage().WebdavProxy() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if utils.SliceContains(conf.TypesMap[conf.ProxyTypes], utils.Ext(filename)) {
|
if utils.SliceContains(conf.SlicesMap[conf.ProxyTypes], utils.Ext(filename)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if utils.SliceContains(conf.TypesMap[conf.TextTypes], utils.Ext(filename)) {
|
if utils.SliceContains(conf.SlicesMap[conf.TextTypes], utils.Ext(filename)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue