MCPcopy Index your code
hub / github.com/TruthHun/BookStack / GenerateMediaSign

Function GenerateMediaSign

utils/jwt.go:56–77  ·  view source on GitHub ↗

GenerateSign 生成token

(path string, unixNano int64, expire ...time.Duration)

Source from the content-addressed store, hash-verified

54
55// GenerateSign 生成token
56func GenerateMediaSign(path string, unixNano int64, expire ...time.Duration) (sign string, err error) {
57 path = strings.TrimLeft(path, "/")
58 // 默认过期时间为一个月
59 expireDuration := time.Now().Add(30 * 24 * time.Hour)
60 if len(expire) > 0 {
61 expireDuration = time.Now().Add(expire[0])
62 }
63
64 customClaims := &MediaClaims{
65 path,
66 unixNano,
67 jwt.StandardClaims{
68 ExpiresAt: expireDuration.Unix(),
69 },
70 }
71
72 // 将 uid,过期时间作为数据写入 token 中
73 jwtToken := jwt.NewWithClaims(jwt.SigningMethodHS256, customClaims)
74
75 // secret 用于对用户数据进行签名,不能暴露
76 return jwtToken.SignedString([]byte(mediaJwtSecret))
77}
78
79// ParseSign 解析jwt token
80func ParseMediaSign(sign string) (path string, err error) {

Callers 2

ReadMethod · 0.92
handleReleaseV3Method · 0.92

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected