Skip to content

Commit

Permalink
adds logic to upload compressed files with right mime type and right …
Browse files Browse the repository at this point in the history
…content encoding
  • Loading branch information
sprockow committed Nov 2, 2020
1 parent d72b221 commit aff735f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion lib/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function uploadFile(aws, bucketName, filePath, fileKey, headers, sse) {
Bucket: bucketName,
Key: fileKey,
Body: fileBuffer,
ContentType: mime.lookup(filePath)
...getMimeTypeAndContentEncoding(filePath)
};

if (sse) {
Expand Down Expand Up @@ -180,4 +180,24 @@ function groupFilesByOrder(files, orderSpec) {
return [unmatchedFiles].concat(matchedFiles);
}

const ContentEncodingMap = {
gz: 'gzip',
br: 'br'
};

function getMimeTypeAndContentEncoding(filePath) {
const match = /(.+\..+)\.(gz|br)$/.exec(filePath);

if (match) {
const [fullMatch, strippedFilePath, encodingFileEnding] = match;

return {
ContentType: mime.lookup(strippedFilePath),
ContentEncoding: ContentEncodingMap[encodingFileEnding]
};
}

return { ContentType: mime.lookup(filePath) };
}

module.exports = uploadDirectory;

0 comments on commit aff735f

Please sign in to comment.