diff --git a/server/server.go b/server/server.go index 60035d8..36259ba 100644 --- a/server/server.go +++ b/server/server.go @@ -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(), @@ -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 @@ -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