feat: sign of file
This commit is contained in:
@ -88,6 +88,7 @@ func initialSettings() {
|
||||
{Key: "global_readme", Value: "This is global readme", Type: conf.TypeText, Group: model.GLOBAL},
|
||||
{Key: "customize_head", Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||
{Key: "customize_body", Type: conf.TypeText, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||
{Key: "link_expiration", Value: "4", Type: conf.TypeNumber, Group: model.GLOBAL, Flag: model.PRIVATE},
|
||||
// single settings
|
||||
{Key: "token", Value: token, Type: conf.TypeString, Group: model.SINGLE, Flag: model.PRIVATE},
|
||||
}
|
||||
|
30
internal/sign/sign.go
Normal file
30
internal/sign/sign.go
Normal file
@ -0,0 +1,30 @@
|
||||
package sign
|
||||
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/setting"
|
||||
"github.com/alist-org/alist/v3/pkg/sign"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
var instance sign.Sign
|
||||
|
||||
func WithDuration(data string, d time.Duration) string {
|
||||
once.Do(Instance)
|
||||
return instance.Sign(data, time.Now().Add(d).Unix())
|
||||
}
|
||||
|
||||
func NotExpired(data string) string {
|
||||
once.Do(Instance)
|
||||
return instance.Sign(data, 0)
|
||||
}
|
||||
|
||||
func Verify(data string, sign string) error {
|
||||
once.Do(Instance)
|
||||
return instance.Verify(data, sign)
|
||||
}
|
||||
|
||||
func Instance() {
|
||||
instance = sign.NewHMACSign([]byte(setting.GetByKey("token")))
|
||||
}
|
Reference in New Issue
Block a user