修改 aliyun,短信,oss,验证码

This commit is contained in:
chy
2025-06-24 16:22:18 +08:00
parent b02ad91118
commit 8342c92247
21 changed files with 219 additions and 128 deletions

View File

@ -2,6 +2,7 @@ package upload
import (
"context"
"fmt"
"server/utility/ecode"
"server/utility/oss"
"strings"
@ -38,69 +39,7 @@ func (s *sUpload) Upload(ctx context.Context, in *model.UploadIn) (res *model.Up
// 获取图片后缀
exit := strings.Split(fileType, "/")[1]
// 文件名称
fileName := strings.ToLower("image/" + grand.Letters(32) + "." + exit)
// 开始上传图片
client, ok := oss.GetClient("aliyun")
if !ok {
return nil, ecode.Fail.Sub("未配置OSS")
}
uploadRes, err := client.UploadFile(ctx, &model.OssUploadFileInput{
Filename: fileName,
File: in.File,
})
if err != nil {
return nil, err
}
return &model.UploadOut{
Url: uploadRes.Url,
}, nil
}
func (s *sUpload) UploadGameImg(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error) {
// 判断文件格式
fileType := in.File.Header.Get("Content-Type")
if !strings.HasPrefix(fileType, "image/") {
return nil, gerror.New("图片格式错误")
}
//判断图片大小
if in.File.Size > 10*1024*1024 {
return nil, gerror.New("图片大小最多10M")
}
// 获取图片后缀
exit := strings.Split(fileType, "/")[1]
// 文件名称
fileName := strings.ToLower("gameImg/" + grand.Letters(32) + "." + exit)
// 开始上传图片
client, ok := oss.GetClient("aliyun")
if !ok {
return nil, ecode.Fail.Sub("未配置OSS")
}
uploadRes, err := client.UploadFile(ctx, &model.OssUploadFileInput{
Filename: fileName,
File: in.File,
})
if err != nil {
return nil, err
}
return &model.UploadOut{
Url: uploadRes.Url,
}, nil
}
func (s *sUpload) UploadUserImg(ctx context.Context, in *model.UploadIn) (res *model.UploadOut, err error) {
// 判断文件格式
fileType := in.File.Header.Get("Content-Type")
if !strings.HasPrefix(fileType, "image/") {
return nil, gerror.New("图片格式错误")
}
//判断图片大小
if in.File.Size > 10*1024*1024 {
return nil, gerror.New("图片大小最多10M")
}
// 获取图片后缀
exit := strings.Split(fileType, "/")[1]
// 文件名称
fileName := strings.ToLower("userImg/" + grand.Letters(32) + "." + exit)
fileName := strings.ToLower(fmt.Sprintf("%s/%s.%s", in.Type, grand.Letters(32), exit))
// 开始上传图片
client, ok := oss.GetClient("aliyun")
if !ok {