Add CadQuery customizer (#547)
* Rough changes to make the CadQuery integration work with the customizer * Tweak runCQ * Switched to Anaconda * Cleaned up code * Update CadHub after anaconda Related to #547 * Add final tweaks to CQ customizer * Separated out customizer.json from params.json * Changes after discussing CadHub integration * linting runCQ Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit was merged in pull request #547.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
lambdaBaseURL,
|
||||
stlToGeometry,
|
||||
createHealthyResponse,
|
||||
createUnhealthyResponse,
|
||||
timeoutErrorMessage,
|
||||
RenderArgs,
|
||||
DefaultKernelExport,
|
||||
splitGziped,
|
||||
} from '../common'
|
||||
import { CadQueryToCadhubParams } from './cadQueryParams'
|
||||
|
||||
export const render: DefaultKernelExport['render'] = async ({
|
||||
code,
|
||||
settings: { quality = 'low', parameters },
|
||||
}: RenderArgs) => {
|
||||
const body = JSON.stringify({
|
||||
settings: {
|
||||
deflection: quality === 'low' ? 0.35 : 0.11,
|
||||
parameters,
|
||||
},
|
||||
file: code,
|
||||
})
|
||||
try {
|
||||
const response = await fetch(lambdaBaseURL + '/cadquery/stl', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
})
|
||||
if (response.status === 400) {
|
||||
const { error } = await response.json()
|
||||
return {
|
||||
status: 'error',
|
||||
message: {
|
||||
type: 'error',
|
||||
message: error,
|
||||
time: new Date(),
|
||||
},
|
||||
}
|
||||
}
|
||||
if (response.status === 502) {
|
||||
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const text = await new Response(blob).text()
|
||||
const { consoleMessage, customizerParams, type } = splitGziped(text)
|
||||
return createHealthyResponse({
|
||||
type: 'geometry',
|
||||
data: await stlToGeometry(window.URL.createObjectURL(blob)),
|
||||
consoleMessage,
|
||||
date: new Date(),
|
||||
customizerParams: CadQueryToCadhubParams(customizerParams),
|
||||
})
|
||||
} catch (e) {
|
||||
return createUnhealthyResponse(new Date())
|
||||
}
|
||||
}
|
||||
|
||||
const cadQuery: DefaultKernelExport = {
|
||||
render,
|
||||
}
|
||||
|
||||
export default cadQuery
|
||||
Reference in New Issue
Block a user