-
Notifications
You must be signed in to change notification settings - Fork 8
/
oss_signed_token.go
66 lines (56 loc) · 1.43 KB
/
oss_signed_token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package middleware
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/kingwel-xie/k2/common"
"github.com/kingwel-xie/k2/common/api"
cerr "github.com/kingwel-xie/k2/common/error"
)
type PresignTokenRequest struct {
Directory string `json:"directory"`
Filename string `json:"filename"`
Duration int `json:"duration"`
}
type PresignTokenResponse struct {
Vendor string `json:"vendor"`
Token interface{} `json:"token"`
}
type PresignToken struct {
api.Api
}
// PresignToken 预签名令牌
// @Summary 预签名令牌
// @Description 预签名令牌
// @Tags 公共接口
// @Param data body PresignTokenRequest true "data"
// @Failure 500
// @Success 200 {object} PresignTokenResponse "{"code": 200, "data": [...]}"
// @Router /presign-token [post]
// @Security Bearer
func (e PresignToken) PresignToken(c *gin.Context) {
var req PresignTokenRequest
oss := common.Runtime.GetOss()
if oss == nil {
e.Error(cerr.ErrOssUnavailable)
}
err := e.MakeContext(c).
Bind(&req, binding.JSON).
Errors
if err != nil {
e.Error(err)
return
}
//identify := e.GetIdentity()
token, err := oss.GeneratePresignedToken(req.Directory, req.Filename, int64(req.Duration))
if err != nil {
e.Error(err)
return
}
//c.Header("Access-Control-Allow-Methods", "POST")
//c.Header("Access-Control-Allow-Origin", "*")
response := PresignTokenResponse {
Vendor: oss.Name(),
Token: token,
}
e.OK(response, "成功")
}