|
|
@ -89,6 +89,7 @@ func (c *Controller) GetHashObject(ctx context.Context, hash string) (*s3.Object
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64, expire time.Duration, maxParts int) (*InitiateUploadResult, error) {
|
|
|
|
func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64, expire time.Duration, maxParts int) (*InitiateUploadResult, error) {
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
defer log.ZDebug(ctx, "return")
|
|
|
|
|
|
|
|
log.ZInfo(ctx, "InitiateUpload", "hash", hash, "size", expire, "config")
|
|
|
|
if size < 0 {
|
|
|
|
if size < 0 {
|
|
|
|
return nil, errors.New("invalid size")
|
|
|
|
return nil, errors.New("invalid size")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -97,6 +98,7 @@ func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64
|
|
|
|
} else if len(hashBytes) != md5.Size {
|
|
|
|
} else if len(hashBytes) != md5.Size {
|
|
|
|
return nil, errors.New("invalid md5")
|
|
|
|
return nil, errors.New("invalid md5")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "InitiateUpload 33333333333333333333333")
|
|
|
|
partSize, err := c.impl.PartSize(ctx, size)
|
|
|
|
partSize, err := c.impl.PartSize(ctx, size)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -108,11 +110,13 @@ func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64
|
|
|
|
if maxParts > 0 && partNumber > 0 && partNumber < maxParts {
|
|
|
|
if maxParts > 0 && partNumber > 0 && partNumber < maxParts {
|
|
|
|
return nil, fmt.Errorf("too many parts: %d", partNumber)
|
|
|
|
return nil, fmt.Errorf("too many parts: %d", partNumber)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "InitiateUpload 4444444444444444444444444444444")
|
|
|
|
if info, err := c.StatObject(ctx, c.HashPath(hash)); err == nil {
|
|
|
|
if info, err := c.StatObject(ctx, c.HashPath(hash)); err == nil {
|
|
|
|
return nil, &HashAlreadyExistsError{Object: info}
|
|
|
|
return nil, &HashAlreadyExistsError{Object: info}
|
|
|
|
} else if !c.impl.IsNotFound(err) {
|
|
|
|
} else if !c.impl.IsNotFound(err) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "InitiateUpload 55555555555555555555555555555555")
|
|
|
|
if size <= partSize {
|
|
|
|
if size <= partSize {
|
|
|
|
// 预签名上传
|
|
|
|
// 预签名上传
|
|
|
|
key := path.Join(tempPath, c.NowPath(), fmt.Sprintf("%s_%d_%s.presigned", hash, size, c.UUID()))
|
|
|
|
key := path.Join(tempPath, c.NowPath(), fmt.Sprintf("%s_%d_%s.presigned", hash, size, c.UUID()))
|
|
|
@ -120,6 +124,7 @@ func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "InitiateUpload 999999999999999999999999")
|
|
|
|
return &InitiateUploadResult{
|
|
|
|
return &InitiateUploadResult{
|
|
|
|
UploadID: newMultipartUploadID(multipartUploadID{
|
|
|
|
UploadID: newMultipartUploadID(multipartUploadID{
|
|
|
|
Type: UploadTypePresigned,
|
|
|
|
Type: UploadTypePresigned,
|
|
|
@ -140,6 +145,7 @@ func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 分片上传
|
|
|
|
// 分片上传
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "InitiateUpload 66666666666666666666666666666666")
|
|
|
|
upload, err := c.impl.InitiateMultipartUpload(ctx, c.HashPath(hash))
|
|
|
|
upload, err := c.impl.InitiateMultipartUpload(ctx, c.HashPath(hash))
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
@ -158,6 +164,7 @@ func (c *Controller) InitiateUpload(ctx context.Context, hash string, size int64
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "InitiateUpload 7777777777777777777777777")
|
|
|
|
return &InitiateUploadResult{
|
|
|
|
return &InitiateUploadResult{
|
|
|
|
UploadID: newMultipartUploadID(multipartUploadID{
|
|
|
|
UploadID: newMultipartUploadID(multipartUploadID{
|
|
|
|
Type: UploadTypeMultipart,
|
|
|
|
Type: UploadTypeMultipart,
|
|
|
|