Skip to content

Commit

Permalink
fix: fix complexity problem
Browse files Browse the repository at this point in the history
fix complexity problem
generateDownloadUrl
  • Loading branch information
Zherphy committed Nov 8, 2024
1 parent 1328ba4 commit 97d0b74
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,7 @@ func (s *server) operateRequestObject(resp batch.Response, req batch.Request) {
getObjectInput.Expires = int(s.ttl / time.Second)
getObjectInput.Headers = map[string]string{"Content-Type": "application/octet-stream"}
// 生成下载对象的带授权信息的URL
getObjectOutput, err := s.client.CreateSignedUrl(getObjectInput)
if err != nil {
panic(err)
}
v, err := url.Parse(getObjectOutput.SignedUrl)
if err == nil {
v.Host = s.cdnDomain
v.Scheme = "https"
} else {
logrus.Infof("%s cannot be parsed", getObjectOutput.SignedUrl)
panic(err)
}
v := s.generateDownloadUrl(getObjectInput)

out.Actions = &batch.Actions{
Download: &batch.Action{
Expand Down Expand Up @@ -256,6 +245,24 @@ func (s *server) operateRequestObject(resp batch.Response, req batch.Request) {
}
}

// 生成下载对象的带授权信息的URL
func (s *server) generateDownloadUrl(getObjectInput *obs.CreateSignedUrlInput) *url.URL {
// 生成下载对象的带授权信息的URL
getObjectOutput, err := s.client.CreateSignedUrl(getObjectInput)
if err != nil {
panic(err)
}
v, err := url.Parse(getObjectOutput.SignedUrl)
if err == nil {
v.Host = s.cdnDomain
v.Scheme = "https"
} else {
logrus.Infof("%s cannot be parsed", getObjectOutput.SignedUrl)
panic(err)
}
return v
}

func (s *server) healthCheck(w http.ResponseWriter, r *http.Request) {
response := batch.SuccessResponse{
Message: "Success",
Expand Down

0 comments on commit 97d0b74

Please sign in to comment.