统一上传文件不区分图片、视频接口,素材中心私有化

This commit is contained in:
xh
2025-08-27 03:17:40 +08:00
parent a58c1360d7
commit 606bcbef0a
17 changed files with 296 additions and 213 deletions

View File

@@ -4,8 +4,10 @@ import (
"crypto/md5"
"encoding/hex"
"encoding/json"
"io"
"math"
"math/rand"
"mime/multipart"
"os"
"reflect"
"strconv"
@@ -45,6 +47,20 @@ func (tu toolsUtil) MakeMd5(data string) string {
return hex.EncodeToString(sum[:])
}
// GetFileMD5 获取文件MD5
func (tu toolsUtil) GetFileMD5(file *multipart.FileHeader) (string, error) {
f, err := file.Open()
if err != nil {
return "", err
}
defer f.Close()
hash := md5.New()
if _, err := io.Copy(hash, f); err != nil {
return "", err
}
return hex.EncodeToString(hash.Sum(nil)), nil
}
// MakeToken 生成唯一Token
func (tu toolsUtil) MakeToken() string {
ms := time.Now().UnixMilli()