mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-19 20:26:26 +08:00

* Enable blank issue * chore(README.md): update docs (temporally) * Update FUNDING.yml * chore: purge README.md * chore: change module name to OpenListTeam/OpenList * fix: fix link errors * chore: remove v3 in module name * fix: resolve some conficts * fix: resolve conficts * docs: update with latest file --------- Co-authored-by: ShenLin <773933146@qq.com> Co-authored-by: Hantong Chen <cxwdyx620@gmail.com> Co-authored-by: joshua <i@joshua.su> Co-authored-by: Hantong Chen <70561268+cxw620@users.noreply.github.com>
42 lines
850 B
Go
42 lines
850 B
Go
package sign
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/OpenListTeam/OpenList/internal/conf"
|
|
"github.com/OpenListTeam/OpenList/internal/setting"
|
|
"github.com/OpenListTeam/OpenList/pkg/sign"
|
|
)
|
|
|
|
var once sync.Once
|
|
var instance sign.Sign
|
|
|
|
func Sign(data string) string {
|
|
expire := setting.GetInt(conf.LinkExpiration, 0)
|
|
if expire == 0 {
|
|
return NotExpired(data)
|
|
} else {
|
|
return WithDuration(data, time.Duration(expire)*time.Hour)
|
|
}
|
|
}
|
|
|
|
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.GetStr(conf.Token)))
|
|
}
|