fix 上传文件判断
This commit is contained in:
parent
bc8a3be3bc
commit
b8de590d99
@ -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,6 +74,10 @@ func (s *sUpload) UploadFile(ctx context.Context,
|
||||
existsFile, err = service.SysAttachment().GetByMd5(ctx, md5)
|
||||
liberr.ErrIsNil(ctx, err, "获取文件信息失败")
|
||||
if existsFile != nil {
|
||||
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,
|
||||
@ -82,6 +87,7 @@ func (s *sUpload) UploadFile(ctx context.Context,
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
uploader := upload.GetUploader(upload.UploaderType(source))
|
||||
if uploader == nil {
|
||||
liberr.ErrIsNil(ctx, errors.New("没有找到上传适配器"))
|
||||
@ -266,6 +272,10 @@ func (s *sUpload) CheckMultipart(ctx context.Context, req *model.CheckMultipartR
|
||||
liberr.ErrIsNil(ctx, err, "获取文件信息失败")
|
||||
res = new(model.CheckMultipartRes)
|
||||
if existsFile != nil {
|
||||
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,
|
||||
@ -275,6 +285,7 @@ func (s *sUpload) CheckMultipart(ctx context.Context, req *model.CheckMultipartR
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
uploader := upload.GetUploader(upload.UploaderType(req.DriverType))
|
||||
if uploader == nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user