Attempt to at move app into app sub dir

This commit is contained in:
Kurt Hutten
2021-05-01 07:32:21 +10:00
parent 9db76458d1
commit 78677a99f8
220 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,66 @@
import { lambdaBaseURL } from './common'
export const render = async ({ code }) => {
const body = JSON.stringify({
settings: {},
file: code,
})
try {
const response = await fetch(lambdaBaseURL + '/cadquery/stl', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body,
})
if (response.status === 400) {
// TODO add proper error messages for CadQuery
const { error } = await response.json()
const cleanedErrorMessage = error.replace(
/["|']\/tmp\/.+\/main.scad["|']/g,
"'main.scad'"
)
return {
status: 'error',
message: {
type: 'error',
message: cleanedErrorMessage,
time: new Date(),
},
}
}
const data = await response.json()
return {
status: 'healthy',
objectData: {
type: 'stl',
data: data.imageBase64,
},
message: {
type: 'message',
message: data.result || 'Successful Render',
time: new Date(),
},
}
} catch (e) {
// TODO handle errors better
// I think we should display something overlayed on the viewer window something like "network issue try again"
// and in future I think we need timeouts differently as they maybe from a user trying to render something too complex
// or something with minkowski in it :/ either way something like "render timed out, try again or here are tips to reduce part complexity" with a link talking about $fn and minkowski etc
return {
status: 'error',
message: {
type: 'error',
message: 'network issue',
time: new Date(),
},
}
}
}
const openScad = {
render,
// more functions to come
}
export default openScad

View File

@@ -0,0 +1,3 @@
export const lambdaBaseURL =
process.env.CAD_LAMBDA_BASE_URL ||
'https://wzab9s632b.execute-api.us-east-1.amazonaws.com/prod'

View File

@@ -0,0 +1,7 @@
import openScad from './openScadController'
import cadQuery from './cadQueryController'
export const cadPackages = {
openScad,
cadQuery,
}

View File

@@ -0,0 +1,76 @@
import { lambdaBaseURL } from './common'
export const render = async ({ code, settings }) => {
const pixelRatio = window.devicePixelRatio || 1
const size = {
x: Math.round(settings.viewerSize?.width * pixelRatio),
y: Math.round(settings.viewerSize?.height * pixelRatio),
}
const body = JSON.stringify({
settings: {
size,
camera: settings.camera,
},
file: code,
})
if (!settings.camera.position) {
return
}
try {
const response = await fetch(lambdaBaseURL + '/openscad/preview', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body,
})
if (response.status === 400) {
const { error } = await response.json()
const cleanedErrorMessage = error.replace(
/["|']\/tmp\/.+\/main.scad["|']/g,
"'main.scad'"
)
return {
status: 'error',
message: {
type: 'error',
message: cleanedErrorMessage,
time: new Date(),
},
}
}
const data = await response.json()
return {
status: 'healthy',
objectData: {
type: 'png',
data: data.imageBase64,
},
message: {
type: 'message',
message: data.result,
time: new Date(),
},
}
} catch (e) {
// TODO handle errors better
// I think we should display something overlayed on the viewer window something like "network issue try again"
// and in future I think we need timeouts differently as they maybe from a user trying to render something too complex
// or something with minkowski in it :/ either way something like "render timed out, try again or here are tips to reduce part complexity" with a link talking about $fn and minkowski etc
return {
status: 'error',
message: {
type: 'error',
message: 'network issue',
time: new Date(),
},
}
}
}
const openScad = {
render,
// more functions to come
}
export default openScad