Skip to content

Commit

Permalink
fix(dl): fix yaml config and get object logic (#60)
Browse files Browse the repository at this point in the history
Signed-off-by: wuhuizuo <[email protected]>

Signed-off-by: wuhuizuo <[email protected]>
  • Loading branch information
wuhuizuo authored Dec 15, 2023
1 parent 1c7fb26 commit b64275f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
21 changes: 15 additions & 6 deletions dl/ks3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"io"
"log"
"net/url"
"os"
"path/filepath"

"github.com/ks3sdklib/aws-sdk-go/aws"
"github.com/ks3sdklib/aws-sdk-go/aws/credentials"
Expand All @@ -23,11 +25,11 @@ type ks3srvc struct {
}

func newKS3Client(cfg *pkgks3.Config) *s3.S3 {
var cre = credentials.NewStaticCredentials(cfg.S3AccessKey, cfg.S3SecretKey, "")
var cre = credentials.NewStaticCredentials(cfg.AccessKey, cfg.SecretKey, "")
awsConfig := aws.Config{
Region: cfg.S3Region, // Ref: https://docs.ksyun.com/documents/6761
Region: cfg.Region, // Ref: https://docs.ksyun.com/documents/6761
Credentials: cre,
Endpoint: cfg.S3Endpoint, // Ref: https://docs.ksyun.com/documents/6761
Endpoint: cfg.Endpoint, // Ref: https://docs.ksyun.com/documents/6761
DisableSSL: true,
LogLevel: 0,
LogHTTPBody: false,
Expand Down Expand Up @@ -65,9 +67,16 @@ func (s *ks3srvc) DownloadObject(ctx context.Context, p *ks3.DownloadObjectPaylo
return nil, nil, err
}

res = &ks3.DownloadObjectResult{
Length: *getObjectOutput.ContentLength,
ContentDisposition: *getObjectOutput.ContentDisposition,
res = &ks3.DownloadObjectResult{}
if getObjectOutput != nil {
if getObjectOutput.ContentLength != nil {
res.Length = *getObjectOutput.ContentLength
}
if getObjectOutput.ContentDisposition != nil {
res.ContentDisposition = *getObjectOutput.ContentDisposition
} else {
res.ContentDisposition = `attachment; filename*=UTF-8''` + url.QueryEscape(filepath.Base(p.Key))
}
}

return res, getObjectOutput.Body, nil
Expand Down
11 changes: 4 additions & 7 deletions dl/pkg/ks3/cfg.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package ks3

type Config struct {
S3Region string
S3Bucket string
S3Endpoint string
S3AccessKey string
S3SecretKey string
BaseUrl string
FileserverUrl string
Region string `yaml:"region,omitempty" json:"region,omitempty"`
Endpoint string `yaml:"endpoint,omitempty" json:"endpoint,omitempty"`
AccessKey string `yaml:"access_key,omitempty" json:"access_key,omitempty"`
SecretKey string `yaml:"secret_key,omitempty" json:"secret_key,omitempty"`
}

0 comments on commit b64275f

Please sign in to comment.