Add s3 integration #317
Reference in New Issue
Block a user
Delete Branch "kurt/s3-integration-316-rebase"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Preview link
Doing so has a number of benefits
through
generated assets, i.e. caching
is faster than return, and there fore the lambdas execute for less time
there is a change to master etc we want to store these assets somewhere
and s3 is an obvious choice
binaryMediaTypes enabled, don't need binary types when dumping in s3
Resolves #316
Example of it working with a large mesh (~40Mb)

@@ -38,0 +22,4 @@const params = {Bucket: process.env.BUCKET,Key: key,}This was me handling CORS preflight endpoints directly because I couldn't get the config working. Turns out it had something to do with binary media types which we don't need since we're not returning the asset directly now.
Return early if the asset is already in the bucket. (based on the key which is a hash of the user's code)
@@ -4,0 +4,4 @@const { createHash } = require('crypto')const CONSOLE_MESSAGE_KEY = 'console-message-b64'function putConsoleMessageInMetadata(consoleMessage) {I'm storing whatever the cad package printed to the terminal when it made the part in metadata, so that I can still display this when returning the cached assets. s3 seems to be pretty sensitive about special characters that can be put in s3 so base64 to the rescue.
@@ -38,0 +72,4 @@})}function loggerWrap(handler) {You can create a signed url for a resource that doesn't exist (I guess aws assume you know if it does or not)
so we have to fetch the object's metadata/headObject to see if it exists, and we can grab the console message from metadata while we're at it.
@@ -38,0 +102,4 @@console.log(`got result in route: ${consoleMessage}, file is: ${fullPath}`)const { readFile } = require('fs/promises')let bufferAfter a part is successful generated the following steps is common to both OpenSCAD and CadQuery so threw it in a function, should probably be cleaned up a little.
Should probably just delete this. I should get around to adding stl download soon. Wouldn't be hard.
@@ -33,4 +28,4 @@# you can overwrite defaults here# stage: dev# region: us-east-1Removing this magically fixed CORS issues I was having as I mentioned in a previous comment.
@@ -29,3 +37,3 @@}, [stlData])}, [url])if (!loadedGeometry) return nullreturn (Because the asset is not being returned directly, but instead a URL to it, I now need to make sure the loading animation stays on while the asset loads, especially for the stls as they can be large.
@@ -4,0 +4,4 @@const { createHash } = require('crypto')const CONSOLE_MESSAGE_KEY = 'console-message-b64'function putConsoleMessageInMetadata(consoleMessage) {Ended up being a bad idea as only 2kb can be store as metadata, and it's definitely possible for logs to exceed this.