Skip to content

Commit

Permalink
Merge pull request #31 from Zherphy/add-repeat-upload-check
Browse files Browse the repository at this point in the history
Add repeat upload check
  • Loading branch information
Zherphy authored Nov 29, 2024
2 parents e00d855 + 4bcf8c3 commit 9808f90
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,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 @@ -256,6 +253,13 @@ 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 {
logrus.Infof("object already exists: %s", in.OID)
return
}

putObjectInput := &obs.CreateSignedUrlInput{}
putObjectInput.Method = obs.HttpMethodPut
putObjectInput.Bucket = s.bucket
Expand All @@ -276,6 +280,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 9808f90

Please sign in to comment.