mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: adapt new uploader for s3 like policy
This commit also fix #730, #713, #756, #5
This commit is contained in:
@@ -174,9 +174,11 @@ func (service *PolicyService) AddCORS() serializer.Response {
|
||||
return serializer.Err(serializer.CodeInternalSetting, "跨域策略添加失败", err)
|
||||
}
|
||||
case "s3":
|
||||
handler := s3.Driver{
|
||||
Policy: &policy,
|
||||
handler, err := s3.NewDriver(&policy)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeInternalSetting, "跨域策略添加失败", err)
|
||||
}
|
||||
|
||||
if err := handler.CORS(); err != nil {
|
||||
return serializer.Err(serializer.CodeInternalSetting, "跨域策略添加失败", err)
|
||||
}
|
||||
|
||||
@@ -61,9 +61,6 @@ type COSCallback struct {
|
||||
|
||||
// S3Callback S3 客户端回调正文
|
||||
type S3Callback struct {
|
||||
Bucket string `form:"bucket"`
|
||||
Etag string `form:"etag"`
|
||||
Key string `form:"key"`
|
||||
}
|
||||
|
||||
// GetBody 返回回调正文
|
||||
@@ -226,17 +223,16 @@ func (service *S3Callback) PreProcess(c *gin.Context) serializer.Response {
|
||||
defer fs.Recycle()
|
||||
|
||||
// 获取回调会话
|
||||
callbackSessionRaw, _ := c.Get("callbackSession")
|
||||
callbackSession := callbackSessionRaw.(*serializer.UploadSession)
|
||||
uploadSession := c.MustGet(filesystem.UploadSessionCtx).(*serializer.UploadSession)
|
||||
|
||||
// 获取文件信息
|
||||
info, err := fs.Handler.(s3.Driver).Meta(context.Background(), callbackSession.SavePath)
|
||||
info, err := fs.Handler.(*s3.Driver).Meta(context.Background(), uploadSession.SavePath)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeUploadFailed, "文件信息不一致", err)
|
||||
}
|
||||
|
||||
// 验证实际文件信息与回调会话中是否一致
|
||||
if callbackSession.Size != info.Size || service.Etag != info.Etag {
|
||||
if uploadSession.Size != info.Size {
|
||||
return serializer.Err(serializer.CodeUploadFailed, "文件信息不一致", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user