Add IsStorageSigned func to judge if Signing is enabled in the storage settings.

It should be working now.
pull/3924/head
Season Shi 2023-03-23 03:19:40 +08:00
parent 21c8e07baa
commit 0e2a22ec8c
No known key found for this signature in database
GPG Key ID: 024D6B1E861D7FB0
3 changed files with 26 additions and 3 deletions

19
internal/sign/storage.go Normal file
View File

@ -0,0 +1,19 @@
package sign
import (
"github.com/alist-org/alist/v3/internal/op"
json "github.com/json-iterator/go"
)
func IsStorageSigned(rawPath string) bool {
storage := op.GetBalancedStorage(rawPath).GetStorage()
var jsonData = map[string]interface{}{}
err := json.Unmarshal([]byte(storage.Addition), &jsonData)
if err != nil {
return false
}
if jsonData["sign"] == "true" {
return true
}
return false
}

View File

@ -264,7 +264,7 @@ func FsGet(c *gin.Context) {
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
query := "?"
if needSign(meta, reqPath) {
query = query + "sign=" + sign.Sign(reqPath) + "&"
query = query + "sign=" + sign.Sign(reqPath)
}
if query == "?" {
query = ""
@ -374,6 +374,9 @@ func needSign(meta *model.Meta, path string) bool {
if setting.GetBool(conf.SignAll) {
return true
}
if sign.IsStorageSigned(path) {
return true
}
if meta == nil || meta.Password == "" {
return false
}

View File

@ -36,8 +36,6 @@ func Down(c *gin.Context) {
return
}
}
// verify token
c.Next()
}
@ -51,6 +49,9 @@ func needSign(meta *model.Meta, path string) bool {
if setting.GetBool(conf.SignAll) {
return true
}
if sign.IsStorageSigned(path) {
return true
}
if meta == nil || meta.Password == "" {
return false
}