diff --git a/app/api/src/docker/aws-emulator.js b/app/api/src/docker/aws-emulator.js index d237030..19f0275 100644 --- a/app/api/src/docker/aws-emulator.js +++ b/app/api/src/docker/aws-emulator.js @@ -26,7 +26,7 @@ app.post('/cadquery/stl', async (req, res) => { console.log('making post request to 5060') try { const { data } = await axios.post(invocationURL(5060), { - body: req.body, + body: JSON.stringify(req.body), }) res.status(data.statusCode) res.send(data.body) diff --git a/app/api/src/docker/cadquery/Dockerfile b/app/api/src/docker/cadquery/Dockerfile index c1ebd13..4e91f91 100644 --- a/app/api/src/docker/cadquery/Dockerfile +++ b/app/api/src/docker/cadquery/Dockerfile @@ -3,7 +3,7 @@ FROM public.ecr.aws/lts/ubuntu:20.04_stable ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update -qq -RUN apt-get -y -qq install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates xvfb libglew2.1 +RUN apt-get -y -qq install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates xvfb RUN apt-get update -qq RUN apt-get install -y wget @@ -36,6 +36,7 @@ RUN npm install # Get the distribution copy of cq-cli +RUN apt-get install -y libglew2.1 RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.2-beta.1/cq-cli-Linux-x86_64.zip # Comment the entry above out and uncomment the one below to revert to the stable release # RUN wget https://github.com/CadQuery/cq-cli/releases/download/v2.1.0/cq-cli-Linux-x86_64.zip diff --git a/app/api/src/docker/serverless.yml b/app/api/src/docker/serverless.yml index e380ba4..b721adc 100644 --- a/app/api/src/docker/serverless.yml +++ b/app/api/src/docker/serverless.yml @@ -144,3 +144,23 @@ functions: # NewOutput: # Description: "Description for the output" # Value: "Some output value" +resources: + Resources: + GatewayResponseDefault4XX: + Type: 'AWS::ApiGateway::GatewayResponse' + Properties: + ResponseParameters: + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" + gatewayresponse.header.Access-Control-Allow-Headers: "'*'" + ResponseType: DEFAULT_4XX + RestApiId: + Ref: 'ApiGatewayRestApi' + GatewayResponseDefault5XX: + Type: 'AWS::ApiGateway::GatewayResponse' + Properties: + ResponseParameters: + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" + gatewayresponse.header.Access-Control-Allow-Headers: "'*'" + ResponseType: DEFAULT_5XX + RestApiId: + Ref: 'ApiGatewayRestApi' diff --git a/app/api/src/lib/owner.js b/app/api/src/lib/owner.js index e6b934e..7a03bbc 100644 --- a/app/api/src/lib/owner.js +++ b/app/api/src/lib/owner.js @@ -12,6 +12,9 @@ export const requireOwnership = async ({ userId, userName, partId } = {}) => { } if (context.currentUser.roles?.includes('admin')) { + if (context.currentUser?.sub === '5cea3906-1e8e-4673-8f0d-89e6a963c096') { + throw new ForbiddenError("That's a local admin ONLY.") + } return } diff --git a/app/web/src/components/PartProfile/PartProfile.js b/app/web/src/components/PartProfile/PartProfile.js index 222a47b..4159333 100644 --- a/app/web/src/components/PartProfile/PartProfile.js +++ b/app/web/src/components/PartProfile/PartProfile.js @@ -27,7 +27,7 @@ const PartProfile = ({ const [isInvalid, setIsInvalid] = useState(false) const { currentUser } = useAuth() const editorRef = useRef(null) - const canEdit = currentUser?.sub === userPart.id + const canEdit = currentUser?.sub === userPart.id || currentUser?.roles.includes('admin') const isImageEditable = !isEditable && canEdit // image is editable when not in profile edit mode in order to separate them as it's too hard too to upload an image to cloudinary temporarily until the use saves (and maybe have to clean up) for the time being const part = userPart?.Part const emotes = countEmotes(part?.Reaction) diff --git a/app/web/src/helpers/cadPackages/cadQueryController.js b/app/web/src/helpers/cadPackages/cadQueryController.js index e630097..950d5d6 100644 --- a/app/web/src/helpers/cadPackages/cadQueryController.js +++ b/app/web/src/helpers/cadPackages/cadQueryController.js @@ -3,6 +3,7 @@ import { stlToGeometry, createHealthyResponse, createUnhealthyResponse, + timeoutErrorMessage, } from './common' export const render = async ({ code }) => { @@ -29,6 +30,9 @@ export const render = async ({ code }) => { }, } } + if (response.status === 502) { + return createUnhealthyResponse(new Date(), timeoutErrorMessage) + } const data = await response.json() const geometry = await stlToGeometry(data.url) return createHealthyResponse({ diff --git a/app/web/src/helpers/cadPackages/common.js b/app/web/src/helpers/cadPackages/common.js index 00de304..293725b 100644 --- a/app/web/src/helpers/cadPackages/common.js +++ b/app/web/src/helpers/cadPackages/common.js @@ -2,7 +2,7 @@ import { STLLoader } from 'three/examples/jsm/loaders/STLLoader' export const lambdaBaseURL = process.env.CAD_LAMBDA_BASE_URL || - 'https://oxt2p7ddgj.execute-api.us-east-1.amazonaws.com/prod' + 'https://2inlbple1b.execute-api.us-east-1.amazonaws.com/prod2' export const stlToGeometry = (url) => new Promise((resolve, reject) => { @@ -38,3 +38,5 @@ export function createUnhealthyResponse(date, message = 'network issue') { }, } } + +export const timeoutErrorMessage = `timeout: We're currently limited a 30s execution time. You can try again, sometimes it works the second time` diff --git a/app/web/src/helpers/cadPackages/openScadController.js b/app/web/src/helpers/cadPackages/openScadController.js index 365b8ae..80e1587 100644 --- a/app/web/src/helpers/cadPackages/openScadController.js +++ b/app/web/src/helpers/cadPackages/openScadController.js @@ -3,6 +3,7 @@ import { stlToGeometry, createHealthyResponse, createUnhealthyResponse, + timeoutErrorMessage, } from './common' export const render = async ({ code, settings }) => { @@ -49,6 +50,9 @@ export const render = async ({ code, settings }) => { const cleanedErrorMessage = cleanError(error) return createUnhealthyResponse(new Date(), cleanedErrorMessage) } + if (response.status === 502) { + return createUnhealthyResponse(new Date(), timeoutErrorMessage) + } const data = await response.json() const type = data.type !== 'stl' ? 'png' : 'geometry' const newData = data.type !== 'stl' ? data.url : stlToGeometry(data.url) @@ -81,6 +85,9 @@ export const stl = async ({ code, settings }) => { const cleanedErrorMessage = cleanError(error) return createUnhealthyResponse(new Date(), cleanedErrorMessage) } + if (response.status === 502) { + return createUnhealthyResponse(new Date(), timeoutErrorMessage) + } const data = await response.json() const geometry = await stlToGeometry(data.url) return createHealthyResponse({