Run curv inside of /tmp
When exporting an stl it writes temporary files which is not allowed when deployed to aws unless it's in temp.
This commit is contained in:
@@ -9,12 +9,13 @@ const stl = async (req, _context, callback) => {
|
||||
console.log('eventBody', eventBody)
|
||||
|
||||
const { file, settings } = JSON.parse(eventBody)
|
||||
const { error, consoleMessage, fullPath } = await runCQ({ file, settings })
|
||||
const { error, consoleMessage, fullPath, tempFile } = await runCQ({ file, settings })
|
||||
await storeAssetAndReturnUrl({
|
||||
error,
|
||||
callback,
|
||||
fullPath,
|
||||
consoleMessage,
|
||||
tempFile
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export const runCQ = async ({
|
||||
15000,
|
||||
true
|
||||
)
|
||||
return { consoleMessage, fullPath }
|
||||
return { consoleMessage, fullPath, tempFile }
|
||||
} catch (error) {
|
||||
return { error: consoleMessage || error, fullPath }
|
||||
}
|
||||
|
||||
@@ -104,11 +104,13 @@ export async function storeAssetAndReturnUrl({
|
||||
callback,
|
||||
fullPath,
|
||||
consoleMessage,
|
||||
tempFile
|
||||
}: {
|
||||
error: string
|
||||
callback: Function
|
||||
fullPath: string
|
||||
consoleMessage: string
|
||||
tempFile: string
|
||||
}) {
|
||||
if (error) {
|
||||
const response = {
|
||||
|
||||
@@ -9,7 +9,7 @@ const preview = async (req, _context, callback) => {
|
||||
console.log('eventBody', eventBody)
|
||||
|
||||
const { file, settings } = JSON.parse(eventBody)
|
||||
const { error, consoleMessage, fullPath } = await runCurv({
|
||||
const { error, consoleMessage, fullPath, tempFile } = await runCurv({
|
||||
file,
|
||||
settings,
|
||||
})
|
||||
@@ -18,6 +18,7 @@ const preview = async (req, _context, callback) => {
|
||||
callback,
|
||||
fullPath,
|
||||
consoleMessage,
|
||||
tempFile,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,7 +29,7 @@ const stl = async (req, _context, callback) => {
|
||||
console.log(eventBody, 'eventBody')
|
||||
|
||||
const { file, settings } = JSON.parse(eventBody)
|
||||
const { error, consoleMessage, fullPath } = await stlExport({
|
||||
const { error, consoleMessage, fullPath, tempFile } = await stlExport({
|
||||
file,
|
||||
settings,
|
||||
})
|
||||
@@ -37,6 +38,7 @@ const stl = async (req, _context, callback) => {
|
||||
callback,
|
||||
fullPath,
|
||||
consoleMessage,
|
||||
tempFile,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ export const runCurv = async ({
|
||||
consoleMessage?: string
|
||||
fullPath?: string
|
||||
customizerPath?: string
|
||||
tempFile?: string
|
||||
}> => {
|
||||
const tempFile = await writeFiles(
|
||||
[
|
||||
@@ -67,7 +68,7 @@ export const runCurv = async ({
|
||||
`cat ${imPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
|
||||
15000
|
||||
)
|
||||
return { consoleMessage, fullPath, customizerPath }
|
||||
return { consoleMessage, fullPath, customizerPath, tempFile }
|
||||
} catch (dirtyError) {
|
||||
return { error: dirtyError }
|
||||
}
|
||||
@@ -90,11 +91,12 @@ export const stlExport = async ({ file, settings: { parameters } } = {}) => {
|
||||
const fullPath = `/tmp/${tempFile}/output.gz`
|
||||
const stlPath = `/tmp/${tempFile}/output.stl`
|
||||
const command = [
|
||||
'curv',
|
||||
'(cd /tmp && curv',
|
||||
'-o', stlPath,
|
||||
'-O jit',
|
||||
'-O vsize=0.4',
|
||||
'-O vsize=0.6',
|
||||
`/tmp/${tempFile}/main.curv`,
|
||||
')',
|
||||
].join(' ')
|
||||
|
||||
try {
|
||||
@@ -113,10 +115,10 @@ export const stlExport = async ({ file, settings: { parameters } } = {}) => {
|
||||
tempFile
|
||||
)
|
||||
await runCommand(
|
||||
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
|
||||
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath} && rm ${stlPath}`,
|
||||
15000
|
||||
)
|
||||
return { consoleMessage, fullPath }
|
||||
return { consoleMessage, fullPath, tempFile }
|
||||
} catch (error) {
|
||||
return { error, fullPath }
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ const preview = async (req, _context, callback) => {
|
||||
console.log('eventBody', eventBody)
|
||||
|
||||
const { file, settings } = JSON.parse(eventBody)
|
||||
const { error, consoleMessage, fullPath } = await runScad({
|
||||
const { error, consoleMessage, fullPath, tempFile } = await runScad({
|
||||
file,
|
||||
settings,
|
||||
})
|
||||
@@ -18,6 +18,7 @@ const preview = async (req, _context, callback) => {
|
||||
callback,
|
||||
fullPath,
|
||||
consoleMessage,
|
||||
tempFile,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -28,7 +29,7 @@ const stl = async (req, _context, callback) => {
|
||||
console.log(eventBody, 'eventBody')
|
||||
|
||||
const { file, settings } = JSON.parse(eventBody)
|
||||
const { error, consoleMessage, fullPath } = await stlExport({
|
||||
const { error, consoleMessage, fullPath, tempFile } = await stlExport({
|
||||
file,
|
||||
settings,
|
||||
})
|
||||
@@ -37,6 +38,7 @@ const stl = async (req, _context, callback) => {
|
||||
callback,
|
||||
fullPath,
|
||||
consoleMessage,
|
||||
tempFile,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ export const runScad = async ({
|
||||
consoleMessage?: string
|
||||
fullPath?: string
|
||||
customizerPath?: string
|
||||
tempFile?: string
|
||||
}> => {
|
||||
const tempFile = await writeFiles(
|
||||
[
|
||||
@@ -88,7 +89,7 @@ export const runScad = async ({
|
||||
`cat ${imPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
|
||||
15000
|
||||
)
|
||||
return { consoleMessage, fullPath, customizerPath }
|
||||
return { consoleMessage, fullPath, customizerPath, tempFile }
|
||||
} catch (dirtyError) {
|
||||
return { error: cleanOpenScadError(dirtyError) }
|
||||
}
|
||||
@@ -143,7 +144,7 @@ export const stlExport = async ({ file, settings: { parameters } } = {}) => {
|
||||
`cat ${stlPath} /var/task/cadhub-concat-split /tmp/${tempFile}/metadata.json | gzip > ${fullPath}`,
|
||||
15000
|
||||
)
|
||||
return { consoleMessage, fullPath, customizerPath }
|
||||
return { consoleMessage, fullPath, customizerPath, tempFile }
|
||||
} catch (error) {
|
||||
return { error, fullPath }
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ functions:
|
||||
timeout: 30
|
||||
environment:
|
||||
BUCKET: cad-preview-bucket-prod-001
|
||||
|
||||
cadquerystl:
|
||||
image:
|
||||
name: cadqueryimage
|
||||
@@ -102,6 +103,7 @@ functions:
|
||||
timeout: 30
|
||||
environment:
|
||||
BUCKET: cad-preview-bucket-prod-001
|
||||
|
||||
curvpreview:
|
||||
image:
|
||||
name: curvimage
|
||||
@@ -115,8 +117,19 @@ functions:
|
||||
method: post
|
||||
cors: true
|
||||
timeout: 25
|
||||
environment:
|
||||
BUCKET: cad-preview-bucket-prod-001
|
||||
curvstl:
|
||||
image:
|
||||
name: curvimage
|
||||
command:
|
||||
- js/curv.stl
|
||||
entryPoint:
|
||||
- '/entrypoint.sh'
|
||||
events:
|
||||
- http:
|
||||
path: curv/stl
|
||||
method: post
|
||||
cors: true
|
||||
timeout: 30
|
||||
# The following are a few example events you can configure
|
||||
# NOTE: Please make sure to change your handler code to work with those events
|
||||
# Check the event documentation for details
|
||||
|
||||
@@ -25,7 +25,7 @@ const IdeViewer = ({
|
||||
})
|
||||
thunkDispatch((dispatch, getState) => {
|
||||
const state = getState()
|
||||
if (['png', 'INIT'].includes(state?.objectData?.type)) {
|
||||
if (['png', 'INIT'].includes(state?.objectData?.type) && (ideType === 'openscad' || state?.objectData?.type === 'INIT' || !state?.objectData?.type)) {
|
||||
dispatch({ type: 'setLoading' })
|
||||
requestRender({
|
||||
state,
|
||||
|
||||
@@ -218,7 +218,7 @@ export function PureIdeViewer({
|
||||
)}
|
||||
<div // eslint-disable-line jsx-a11y/no-static-element-interactions
|
||||
className={`opacity-0 absolute inset-0 transition-opacity duration-500 ${
|
||||
ideType === 'curv' ? // TODO hide axes while curve doesn't have a controllable camera
|
||||
ideType === 'curv' && dataType === 'png' ? // TODO hide axes while curve doesn't have a controllable camera
|
||||
'opacity-0' :
|
||||
!(isDragging || dataType !== 'png')
|
||||
? 'hover:opacity-50'
|
||||
@@ -230,7 +230,7 @@ export function PureIdeViewer({
|
||||
<Controls
|
||||
onDragStart={() => setIsDragging(true)}
|
||||
onInit={onInit}
|
||||
onCameraChange={onCameraChange}
|
||||
onCameraChange={() => {onCameraChange(); setIsDragging(false)}}
|
||||
controlsRef={controlsRef}
|
||||
camera={camera}
|
||||
/>
|
||||
|
||||
@@ -14,33 +14,12 @@ export const render = async ({ code, settings }: RenderArgs) => {
|
||||
x: Math.round(settings.viewerSize?.width * pixelRatio),
|
||||
y: Math.round(settings.viewerSize?.height * pixelRatio),
|
||||
}
|
||||
const round1dec = (number) => Math.round((number + Number.EPSILON) * 10) / 10
|
||||
const body = JSON.stringify({
|
||||
settings: {
|
||||
size,
|
||||
viewAll: settings.viewAll,
|
||||
parameters: settings.parameters,
|
||||
camera: {
|
||||
// rounding to give our caching a chance to sometimes work
|
||||
...settings.camera,
|
||||
dist: round1dec(settings.camera.dist),
|
||||
position: {
|
||||
x: round1dec(settings.camera.position.x),
|
||||
y: round1dec(settings.camera.position.y),
|
||||
z: round1dec(settings.camera.position.z),
|
||||
},
|
||||
rotation: {
|
||||
x: round1dec(settings.camera.rotation.x),
|
||||
y: round1dec(settings.camera.rotation.y),
|
||||
z: round1dec(settings.camera.rotation.z),
|
||||
},
|
||||
},
|
||||
},
|
||||
file: code,
|
||||
})
|
||||
if (!settings.camera.position) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await fetch(lambdaBaseURL + '/curv/preview', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user