fix 上传文件判断

This commit is contained in:
yxh 2025-06-25 22:30:39 +08:00
parent bc8a3be3bc
commit b8de590d99
2 changed files with 28 additions and 17 deletions

View File

@ -16,6 +16,7 @@ import (
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gfile"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/gconv"
@ -73,14 +74,19 @@ func (s *sUpload) UploadFile(ctx context.Context,
existsFile, err = service.SysAttachment().GetByMd5(ctx, md5)
liberr.ErrIsNil(ctx, err, "获取文件信息失败")
if existsFile != nil {
result = &model.UploadResponse{
Size: existsFile.Size,
Path: existsFile.Path,
FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path,
Name: existsFile.Name,
Type: existsFile.MimeType,
if !gfile.Exists(g.Cfg().MustGet(ctx, "server.serverRoot").String() + "/" + existsFile.Path) {
//文件不存在删除sysAttachment表中不存在的条目
_ = service.SysAttachment().Delete(ctx, []int64{existsFile.Id})
} else {
result = &model.UploadResponse{
Size: existsFile.Size,
Path: existsFile.Path,
FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path,
Name: existsFile.Name,
Type: existsFile.MimeType,
}
return
}
return
}
uploader := upload.GetUploader(upload.UploaderType(source))
if uploader == nil {
@ -266,14 +272,19 @@ func (s *sUpload) CheckMultipart(ctx context.Context, req *model.CheckMultipartR
liberr.ErrIsNil(ctx, err, "获取文件信息失败")
res = new(model.CheckMultipartRes)
if existsFile != nil {
res.Attachment = &model.UploadResponse{
Size: existsFile.Size,
Path: existsFile.Path,
FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path,
Name: existsFile.Name,
Type: existsFile.MimeType,
if !gfile.Exists(g.Cfg().MustGet(ctx, "server.serverRoot").String() + "/" + existsFile.Path) {
// 文件不存在删除sysAttachment表中不存在的条目
_ = service.SysAttachment().Delete(ctx, []int64{existsFile.Id})
} else {
res.Attachment = &model.UploadResponse{
Size: existsFile.Size,
Path: existsFile.Path,
FullPath: libUtils.GetDomain(ctx, true) + "/" + existsFile.Path,
Name: existsFile.Name,
Type: existsFile.MimeType,
}
return
}
return
}
uploader := upload.GetUploader(upload.UploaderType(req.DriverType))

View File

@ -9,9 +9,9 @@ package model
// PageReq 公共请求参数
type PageReq struct {
DateRange []string `p:"dateRange"` //日期范围
PageNum int `p:"pageNum"` //当前页码
PageSize int `p:"pageSize"` //每页数
DateRange []string `p:"dateRange"` //日期范围
PageNum int `p:"pageNum"` //当前页码
PageSize int `p:"pageSize"` //每页数
OrderBy string `p:"orderBy" v:"regex:^[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?\\s+(asc|desc|ASC|DESC)(?:\\s*,\\s*[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)?\\s+(asc|desc|ASC|DESC))*$#排序参数不合法"` // 排序方式
}