Skip to content

Commit

Permalink
add: add-repeat-upload-check
Browse files Browse the repository at this point in the history
校验上传文件是否已存在
  • Loading branch information
Zherphy committed Nov 22, 2024
1 parent f5f709d commit 144ba0e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,8 @@ func (s *server) dealWithAuthError(userInRepo auth.UserInRepo, w http.ResponseWr
}

func (s *server) downloadObject(in *batch.RequestObject, out *batch.Object) {
getObjectMetadataInput := &obs.GetObjectMetadataInput{
Bucket: s.bucket,
Key: s.key(in.OID),
}
if metadata, err := s.client.GetObjectMetadata(getObjectMetadataInput); err != nil {
getObjectMetadataInput := s.getObjectMetadataInput(s.bucket, s.key(in.OID))
if metadata, err := s.client.GetObjectMetadata(&getObjectMetadataInput); err != nil {
out.Error = &batch.ObjectError{
Code: 404,
Message: err.Error(),
Expand Down Expand Up @@ -237,6 +234,12 @@ func (s *server) uploadObject(in *batch.RequestObject, out *batch.Object) {
return
}

checkInput := s.getObjectMetadataInput(s.bucket, s.key(in.OID))
_, err := s.client.GetObjectMetadata(&checkInput)
if err == nil {
return
}

putObjectInput := &obs.CreateSignedUrlInput{}
putObjectInput.Method = obs.HttpMethodPut
putObjectInput.Bucket = s.bucket
Expand All @@ -257,6 +260,13 @@ func (s *server) uploadObject(in *batch.RequestObject, out *batch.Object) {
}
}

func (s *server) getObjectMetadataInput(bucket string, key string) obs.GetObjectMetadataInput {
return obs.GetObjectMetadataInput{
Bucket: bucket,
Key: key,
}
}

// 生成下载对象的带授权信息的URL
func (s *server) generateDownloadUrl(getObjectInput *obs.CreateSignedUrlInput) *url.URL {
// 生成下载对象的带授权信息的URL
Expand Down

0 comments on commit 144ba0e

Please sign in to comment.