Skip to content

Commit

Permalink
Merge pull request #10 from isd-sgcu/cdn
Browse files Browse the repository at this point in the history
fix: cdn url
  • Loading branch information
bookpanda authored Jul 16, 2024
2 parents 89e30a3 + 4f50aa9 commit 1f204b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions internal/object/object.repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Repository interface {
Upload(file []byte, bucketName string, objectKey string) (url string, key string, err error)
Delete(bucketName string, objectKey string) (err error)
Get(bucketName string, objectKey string) (url string, err error)
GetURL(bucketName string, objectKey string) string
GetURL(objectKey string) string
}

type repositoryImpl struct {
Expand Down Expand Up @@ -46,7 +46,7 @@ func (r *repositoryImpl) Upload(file []byte, bucketName string, objectKey string
return "", "", errors.Wrap(err, fmt.Sprintf("Couldn't upload object to %v/%v.", bucketName, objectKey))
}

return r.GetURL(bucketName, objectKey), objectKey, nil
return r.GetURL(bucketName), objectKey, nil
}

func (r *repositoryImpl) Delete(bucketName string, objectKey string) (err error) {
Expand All @@ -67,7 +67,7 @@ func (r *repositoryImpl) Get(bucketName string, objectKey string) (url string, e
_, cancel := context.WithTimeout(ctx, 50*time.Second)
defer cancel()

url = r.GetURL(bucketName, objectKey)
url = r.GetURL(bucketName)

resp, err := r.httpClient.Get(url)
if err != nil {
Expand All @@ -80,6 +80,6 @@ func (r *repositoryImpl) Get(bucketName string, objectKey string) (url string, e
return url, nil
}

func (r *repositoryImpl) GetURL(bucketName string, objectKey string) string {
return r.conf.CDNEndpoint + "/" + bucketName + "/" + objectKey
func (r *repositoryImpl) GetURL(objectKey string) string {
return r.conf.CDNEndpoint + "/" + objectKey
}
8 changes: 4 additions & 4 deletions internal/object/object.repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (t *ObjectRepositoryTest) TestCreateObjectSuccess() {
url, key, err := repo.Upload([]byte{}, "mock-bucket", "mock-key")
t.Nil(err)
t.Equal("mock-key", key)
t.Equal(repo.GetURL("mock-bucket", "mock-key"), url)
t.Equal(repo.GetURL("mock-key"), url)
}

func (t *ObjectRepositoryTest) TestUploadSuccess() {
Expand All @@ -57,7 +57,7 @@ func (t *ObjectRepositoryTest) TestUploadSuccess() {
url, key, err := repo.Upload([]byte{}, "bucket", "object")
t.Nil(err)
t.Equal("object", key)
t.Equal(repo.GetURL("bucket", "object"), url)
t.Equal(repo.GetURL("object"), url)
}

func (t *ObjectRepositoryTest) TestUploadError() {
Expand Down Expand Up @@ -101,7 +101,7 @@ func (t *ObjectRepositoryTest) TestGetSuccess() {

url, err := repo.Get("bucket", "object")
t.Nil(err)
t.Equal(repo.GetURL("bucket", "object"), url)
t.Equal(repo.GetURL("object"), url)
}

func (t *ObjectRepositoryTest) TestGetError() {
Expand Down Expand Up @@ -130,6 +130,6 @@ func (t *ObjectRepositoryTest) TestGetStatusNotOK() {

func (t *ObjectRepositoryTest) TestGetURL() {
repo := object.NewRepository(t.conf, nil, nil)
url := repo.GetURL("bucket", "object")
url := repo.GetURL("object")
t.Equal(t.mockEndpoint, url)
}
4 changes: 2 additions & 2 deletions internal/object/object.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,6 @@ func (s *serviceImpl) DeleteByKey(_ context.Context, req *proto.DeleteByKeyObjec
}, nil
}

func (s *serviceImpl) GetURL(bucketName string, objectKey string) string {
return "https://" + s.conf.Endpoint + "/" + bucketName + "/" + objectKey
func (s *serviceImpl) GetURL(objectKey string) string {
return s.conf.CDNEndpoint + "/" + objectKey
}
8 changes: 4 additions & 4 deletions mocks/object/object.repository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f204b1

Please sign in to comment.