Skip to content

Commit

Permalink
Merge pull request #1257 from bcgov/dev-rook-RQ-FOIMOD-3551
Browse files Browse the repository at this point in the history
1. set content type for html files 2. correct the path for publishing files
  • Loading branch information
richard-aot authored Jan 7, 2025
2 parents c0df390 + a1068dd commit 0d31918
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
18 changes: 14 additions & 4 deletions computingservices/OpenInfoServices/lib/awslib/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,21 @@ func CopyS3(sourceBucket string, sourcePrefix string, filemappings []AdditionalF
// destKey := destPrefix + sourceKey[len(prefix):]
destKey := destPrefix + strings.ReplaceAll(sourceKey, path.Base(sourceKey), base)

// Determine the content type based on file extension
var contentType string
if strings.EqualFold(filepath.Ext(bucket+"/"+sourceKey), ".html") {
contentType = "text/html"
} else {
// Set default content type or leave it unset
contentType = "application/octet-stream"
}

_, err := svc.CopyObject(context.TODO(), &s3.CopyObjectInput{
Bucket: aws.String(destBucket),
CopySource: aws.String(bucket + "/" + sourceKey),
Key: aws.String(destKey),
ACL: types.ObjectCannedACLPublicRead,
Bucket: aws.String(destBucket),
CopySource: aws.String(bucket + "/" + sourceKey),
Key: aws.String(destKey),
ACL: types.ObjectCannedACLPublicRead,
ContentType: aws.String(contentType),
})
if err != nil {
log.Fatalf("unable to copy item %q, %v", sourceKey, err)
Expand Down
2 changes: 1 addition & 1 deletion computingservices/OpenInfoServices/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func main() {
}

url := awslib.Url{
Loc: s3url + destBucket + "/" + oiprefix + item.Axisrequestid + "/" + item.Axisrequestid + ".html",
Loc: s3url + destBucket + "/" + oiprefix + item.Axisrequestid + "/openinfo/" + item.Axisrequestid + ".html",
LastMod: lastMod,
}
urlset.Urls = append(urlset.Urls, url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func Publish(msg OpenInfoMessage, db *sql.DB) {
{Name: "timestamp", Content: fmt.Sprintf("%d", unixTimestamp)},
{Name: "dc.contributor", Content: msg.Contributor},
{Name: "recorduid", Content: msg.Axisrequestid},
{Name: "recordurl", Content: s3url + oibucket + "/" + oiprefix + msg.Axisrequestid + "/" + msg.Axisrequestid + ".html"},
{Name: "recordurl", Content: s3url + oibucket + "/" + oiprefix + msg.Axisrequestid + "/openinfo/" + msg.Axisrequestid + ".html"},
{Name: "month", Content: now.Format(dateformat_month)},
{Name: "year", Content: now.Format(dateformat_year)},
{Name: "letter", Content: result.LetterNames},
Expand Down

0 comments on commit 0d31918

Please sign in to comment.