feat: add fine-grained control for link signing (#3924)
* Determine whether the URL requires Sign * Add File and Mem based KV NOT TESTED: TokenKV Function * Change Token KV func to common func. Add File based KV func * Remove KV, Remove Token I found that the original Sign function is enough to complete the link signature, and only need to add simple configuration items to meet the requirements. * Add IsStorageSigned func to judge if Signing is enabled in the storage settings. It should be working now. * Add a SIGN button to the management panel. * Add enable_sign to the basic storage struct. Can enable sign for every driver now. Bug: When sign enabled, in download page, Copy link doesn't contain a sign. (Not done yet) * Fix a bug from commit 8f6c25f. Response of fsread function does not contain sign. * Optimize code and follow advices. - Add back public/dist/README.md - Enable sign when DownProxyUrl is enabled - Merge needSign() to isEncrypt() in fsread.go * simplify code --------- Co-authored-by: Andy Hsu <i@nn.ci>
This commit is contained in:
@ -165,6 +165,9 @@ func getReadme(meta *model.Meta, path string) string {
|
||||
}
|
||||
|
||||
func isEncrypt(meta *model.Meta, path string) bool {
|
||||
if common.IsStorageSignEnabled(path) {
|
||||
return true
|
||||
}
|
||||
if meta == nil || meta.Password == "" {
|
||||
return false
|
||||
}
|
||||
@ -260,16 +263,20 @@ func FsGet(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if storage.Config().MustProxy() || storage.GetStorage().WebProxy {
|
||||
query := ""
|
||||
if isEncrypt(meta, reqPath) {
|
||||
query = "?sign=" + sign.Sign(reqPath)
|
||||
}
|
||||
if storage.GetStorage().DownProxyUrl != "" {
|
||||
rawURL = fmt.Sprintf("%s%s?sign=%s",
|
||||
strings.Split(storage.GetStorage().DownProxyUrl, "\n")[0],
|
||||
utils.EncodePath(reqPath, true),
|
||||
sign.Sign(reqPath))
|
||||
} else {
|
||||
rawURL = fmt.Sprintf("%s/p%s?sign=%s",
|
||||
rawURL = fmt.Sprintf("%s/p%s%s",
|
||||
common.GetApiUrl(c.Request),
|
||||
utils.EncodePath(reqPath, true),
|
||||
sign.Sign(reqPath))
|
||||
query)
|
||||
}
|
||||
} else {
|
||||
// file have raw url
|
||||
|
Reference in New Issue
Block a user