fix: 解决打开防盗链报错的问题 (#1230)

pull/1234/head
zhengkunwang223 2 years ago committed by GitHub
parent 488eb319a1
commit e7a9c3814b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1703,7 +1703,7 @@ func (w WebsiteService) UpdateAntiLeech(req request.NginxAntiLeechUpdate) (err e
validDir.Parameters = append(validDir.Parameters, "none") validDir.Parameters = append(validDir.Parameters, "none")
} }
if len(req.ServerNames) > 0 { if len(req.ServerNames) > 0 {
validDir.Parameters = append(validDir.Parameters, "server_names", strings.Join(req.ServerNames, " ")) validDir.Parameters = append(validDir.Parameters, strings.Join(req.ServerNames, " "))
} }
newBlock.Directives = append(newBlock.Directives, validDir) newBlock.Directives = append(newBlock.Directives, validDir)
@ -1768,23 +1768,19 @@ func (w WebsiteService) GetAntiLeech(id uint) (*response.NginxAntiLeechRes, erro
if lDir.GetName() == "valid_referers" { if lDir.GetName() == "valid_referers" {
res.Enable = true res.Enable = true
params := lDir.GetParameters() params := lDir.GetParameters()
serverIndex := 0 for _, param := range params {
serverNameExist := false
for i, param := range params {
if param == "none" { if param == "none" {
res.NoneRef = true res.NoneRef = true
continue
} }
if param == "blocked" { if param == "blocked" {
res.Blocked = true res.Blocked = true
continue
} }
if param == "server_names" { if param == "server_names" {
serverIndex = i continue
serverNameExist = true
} }
} res.ServerNames = append(res.ServerNames, param)
if serverNameExist {
serverNames := params[serverIndex+1:]
res.ServerNames = serverNames
} }
} }
if lDir.GetName() == "if" && lDir.GetParameters()[0] == "($invalid_referer)" { if lDir.GetName() == "if" && lDir.GetParameters()[0] == "($invalid_referer)" {

Loading…
Cancel
Save