mirror of
https://github.com/thegeeklab/wp-s3-action.git
synced 2024-11-21 14:50:39 +00:00
Adding support for uploading files with Content Encoding
This commit is contained in:
parent
81ee08a5a5
commit
748c4417a3
55
aws.go
55
aws.go
@ -82,6 +82,19 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
}
|
||||
}
|
||||
|
||||
var contentEncoding string
|
||||
if a.vargs.ContentEncoding.IsString() {
|
||||
contentEncoding = a.vargs.ContentEncoding.String()
|
||||
} else if !a.vargs.ContentEncoding.IsEmpty() {
|
||||
encodingMap := a.vargs.ContentEncoding.Map()
|
||||
for patternExt := range encodingMap {
|
||||
if patternExt == fileExt {
|
||||
contentEncoding = encodingMap[patternExt]
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metadata := map[string]*string{}
|
||||
vmap := a.vargs.Metadata.Map()
|
||||
if len(vmap) > 0 {
|
||||
@ -108,15 +121,21 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
debug("Uploading \"%s\" with Content-Type \"%s\" and permissions \"%s\"", local, contentType, access)
|
||||
_, err = a.client.PutObject(&s3.PutObjectInput{
|
||||
debug("\"%s\" not found in bucket, uploading with Content-Type \"%s\" and permissions \"%s\"", local, contentType, access)
|
||||
var putObject = &s3.PutObjectInput{
|
||||
Bucket: aws.String(a.vargs.Bucket),
|
||||
Key: aws.String(remote),
|
||||
Body: file,
|
||||
ContentType: aws.String(contentType),
|
||||
ACL: aws.String(access),
|
||||
Metadata: metadata,
|
||||
})
|
||||
}
|
||||
|
||||
if(len(contentEncoding) > 0) {
|
||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
_, err = a.client.PutObject(putObject)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -137,6 +156,16 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.ContentEncoding == nil && contentEncoding != "" {
|
||||
debug("Content-Encoding has changed from unset to %s", contentEncoding)
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && head.ContentEncoding != nil && contentEncoding != *head.ContentEncoding {
|
||||
debug("Content-Encoding has changed from %s to %s", *head.ContentEncoding, contentEncoding)
|
||||
shouldCopy = true
|
||||
}
|
||||
|
||||
if !shouldCopy && len(head.Metadata) != len(metadata) {
|
||||
debug("Count of metadata values has changed for %s", local)
|
||||
shouldCopy = true
|
||||
@ -193,7 +222,7 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
}
|
||||
|
||||
debug("Updating metadata for \"%s\" Content-Type: \"%s\", ACL: \"%s\"", local, contentType, access)
|
||||
_, err = a.client.CopyObject(&s3.CopyObjectInput{
|
||||
var copyObject = &s3.CopyObjectInput{
|
||||
Bucket: aws.String(a.vargs.Bucket),
|
||||
Key: aws.String(remote),
|
||||
CopySource: aws.String(fmt.Sprintf("%s/%s", a.vargs.Bucket, remote)),
|
||||
@ -201,7 +230,13 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
ContentType: aws.String(contentType),
|
||||
Metadata: metadata,
|
||||
MetadataDirective: aws.String("REPLACE"),
|
||||
})
|
||||
}
|
||||
|
||||
if(len(contentEncoding) > 0) {
|
||||
copyObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
_, err = a.client.CopyObject(copyObject)
|
||||
return err
|
||||
} else {
|
||||
_, err = file.Seek(0, 0)
|
||||
@ -210,14 +245,20 @@ func (a *AWS) Upload(local, remote string) error {
|
||||
}
|
||||
|
||||
debug("Uploading \"%s\" with Content-Type \"%s\" and permissions \"%s\"", local, contentType, access)
|
||||
_, err = a.client.PutObject(&s3.PutObjectInput{
|
||||
var putObject = &s3.PutObjectInput{
|
||||
Bucket: aws.String(a.vargs.Bucket),
|
||||
Key: aws.String(remote),
|
||||
Body: file,
|
||||
ContentType: aws.String(contentType),
|
||||
ACL: aws.String(access),
|
||||
Metadata: metadata,
|
||||
})
|
||||
}
|
||||
|
||||
if(len(contentEncoding) > 0){
|
||||
putObject.ContentEncoding = aws.String(contentEncoding)
|
||||
}
|
||||
|
||||
_, err = a.client.PutObject(putObject)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
1
types.go
1
types.go
@ -12,6 +12,7 @@ type PluginArgs struct {
|
||||
Delete bool `json:"delete"`
|
||||
Access StringMap `json:"acl"`
|
||||
ContentType StringMap `json:"content_type"`
|
||||
ContentEncoding StringMap `json:"content_encoding"`
|
||||
Metadata DeepStringMap `json:"metadata"`
|
||||
Redirects map[string]string `json:"redirects"`
|
||||
CloudFrontDistribution string `json:"cloudfront_distribution_id"`
|
||||
|
Loading…
Reference in New Issue
Block a user