feat(files): enable upload limiter

This commit is contained in:
hexxa 2021-08-07 21:06:43 +08:00 committed by Hexxa
parent e01f5f8351
commit fd5da3db37
5 changed files with 118 additions and 0 deletions

View file

@ -7,6 +7,8 @@ import (
"path/filepath"
"github.com/gin-gonic/gin"
"github.com/ihexxa/quickshare/src/cryptoutil"
)
var (
@ -137,3 +139,22 @@ func UploadPath(userID, relFilePath string) string {
func UploadFolder(userID string) string {
return filepath.Join(userID, UploadDir)
}
func GetUserInfo(tokenStr string, tokenEncDec cryptoutil.ITokenEncDec) (map[string]string, error) {
claims, err := tokenEncDec.FromToken(
tokenStr,
map[string]string{
UserIDParam: "",
UserParam: "",
RoleParam: "",
ExpireParam: "",
},
)
if err != nil {
return nil, err
} else if claims[UserIDParam] == "" || claims[UserParam] == "" {
return nil, errors.New("empty user id or name")
}
return claims, nil
}