Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dl): fix yaml config and get object logic #60

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"`
}