Implement gzip compression for cad artifacts

The stls from CadQuery and OpenSCAD are not compressed and so we're
throwing away bandwidth and taking a performance hit by not gziping.

Gzip for s3 basically needs to be gziped before upload and than have

'content-type'      :  'text/stl'
'content-encoding'  :  'gzip'
set.

https://stackoverflow.com/questions/8080824/how-to-serve-gzipped-assets-from-amazon-s3

The obvious part that needs to change is putObject in
app/api/src/docker/common/utils.js but there might be a few more
nuances.

resolves #391
This commit is contained in:
Kurt Hutten
2021-07-03 08:25:20 +10:00
parent 207eb6790a
commit 70e55a039d
4 changed files with 32 additions and 8 deletions

View File

@@ -117,7 +117,7 @@ async function storeAssetAndReturnUrl({
let buffer
try {
buffer = await readFile(fullPath)
buffer = await readFile(`${fullPath}.gz`)
} catch (e) {
console.log('read file error', e)
const response = {
@@ -134,6 +134,8 @@ async function storeAssetAndReturnUrl({
Key: key,
Body: buffer,
CacheControl: `max-age=${FiveDays}`, // browser caching to stop downloads of the same part
ContentType: 'text/stl',
ContentEncoding: 'gzip',
Metadata: putConsoleMessageInMetadata(consoleMessage),
})
.promise()