| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package router
- import (
- "crypto/md5"
- "file-manger-server/db"
- "file-manger-server/service/dao"
- "file-manger-server/util"
- "fmt"
- "github.com/gin-gonic/gin"
- "strconv"
- "strings"
- "time"
- )
- func UploadInfo(c *gin.Context) {
- //获取用户数据信息
- claims, err := util.ValidateTokenToMyClaims(c.GetHeader("auth-sign"))
- if err != nil {
- c.JSON(200, CreateResultError(400, "token错误"))
- return
- }
- user, err := dao.UserDao{}.GetById(claims.Id)
- if err != nil || user.Id == 0 {
- c.JSON(200, CreateResultError(400, "用户信息错误"))
- return
- }
- tid := ToHexBytes(random16Bytes())
- db.FileUserDao{}.Insert(tid, user.Id)
- c.JSON(200, CreateResultData(gin.H{
- "transactionId": tid,
- }))
- }
- func ToHexBytes(bytes [16]byte) string {
- var hexBytes string
- for b := range bytes {
- hexBytes = fmt.Sprint(hexBytes, fmt.Sprintf("%02X", bytes[b]))
- }
- return strings.TrimSpace(hexBytes)
- }
- func random16Bytes() [16]byte {
- return md5.Sum([]byte(strconv.FormatInt(time.Now().UnixNano(), 10)))
- }
|