Send console message with healthy render
This commit is contained in:
@@ -14,19 +14,8 @@ app.post('/render', async (req, res) => {
|
|||||||
const { data } = await axios.post(invocationURL(5052), {
|
const { data } = await axios.post(invocationURL(5052), {
|
||||||
body: Buffer.from(JSON.stringify(req.body)).toString('base64'),
|
body: Buffer.from(JSON.stringify(req.body)).toString('base64'),
|
||||||
})
|
})
|
||||||
if (data.statusCode !== 200) {
|
res.status(data.statusCode)
|
||||||
res.status(data.statusCode)
|
res.send(data.body)
|
||||||
res.send(res.body)
|
|
||||||
} else {
|
|
||||||
const fileContents = Buffer.from(data.body, 'base64')
|
|
||||||
|
|
||||||
const readStream = new stream.PassThrough()
|
|
||||||
readStream.end(fileContents)
|
|
||||||
|
|
||||||
res.set('Content-disposition', 'attachment; filename=' + 'output')
|
|
||||||
res.set('Content-Type', 'image/png')
|
|
||||||
readStream.pipe(res)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
|
|||||||
@@ -45,11 +45,11 @@ const render = async (req, _context, callback) => {
|
|||||||
console.log(image, 'encoded image')
|
console.log(image, 'encoded image')
|
||||||
const response = {
|
const response = {
|
||||||
statusCode: 200,
|
statusCode: 200,
|
||||||
headers: {
|
body: JSON.stringify({
|
||||||
'content-type': 'image/png',
|
imageBase64: image,
|
||||||
},
|
result,
|
||||||
body: image,
|
tempFile,
|
||||||
isBase64Encoded: true,
|
}),
|
||||||
}
|
}
|
||||||
callback(null, response)
|
callback(null, response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,11 +64,11 @@ async function runCommand(command, timeout = 5000) {
|
|||||||
}
|
}
|
||||||
if (stderr) {
|
if (stderr) {
|
||||||
console.log(`stderr: ${stderr}`)
|
console.log(`stderr: ${stderr}`)
|
||||||
resolve(`stderr: ${stderr}`)
|
resolve(stderr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log(`stdout: ${stdout}`)
|
console.log(`stdout: ${stdout}`)
|
||||||
resolve(`stdout: ${stdout}`)
|
resolve(stdout)
|
||||||
})
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reject('timeout')
|
reject('timeout')
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ const IdeConsole = () => {
|
|||||||
<div className="p-8 border-2 m-2 overflow-y-auto">
|
<div className="p-8 border-2 m-2 overflow-y-auto">
|
||||||
<div>
|
<div>
|
||||||
{state.consoleMessages?.map(({ type, message }, index) => (
|
{state.consoleMessages?.map(({ type, message }, index) => (
|
||||||
<div
|
<pre
|
||||||
className={'font-mono ' + (type === 'error' ? 'text-red-500' : '')}
|
className={'font-mono ' + (type === 'error' ? 'text-red-500' : '')}
|
||||||
key={message + index}
|
key={message + index}
|
||||||
>
|
>
|
||||||
-> {message}
|
{message}
|
||||||
</div>
|
</pre>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -124,8 +124,7 @@ const IdeViewer = () => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setImage(
|
setImage(
|
||||||
state.objectData?.type === 'png' &&
|
state.objectData?.type === 'png' &&
|
||||||
state.objectData?.data &&
|
'data:image/png;base64,' + state.objectData?.data
|
||||||
window.URL.createObjectURL(state.objectData?.data)
|
|
||||||
)
|
)
|
||||||
setIsDragging(false)
|
setIsDragging(false)
|
||||||
}, [state.objectData])
|
}, [state.objectData])
|
||||||
|
|||||||
@@ -50,20 +50,20 @@ export const render = async ({ code, settings }) => {
|
|||||||
status: 'error',
|
status: 'error',
|
||||||
message: {
|
message: {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: cleanedErrorMessage,
|
message: addDateToLog(cleanedErrorMessage),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const data = await response.blob()
|
const data = await response.json()
|
||||||
return {
|
return {
|
||||||
status: 'healthy',
|
status: 'healthy',
|
||||||
objectData: {
|
objectData: {
|
||||||
type: 'png',
|
type: 'png',
|
||||||
data,
|
data: data.imageBase64,
|
||||||
},
|
},
|
||||||
message: {
|
message: {
|
||||||
type: 'message',
|
type: 'message',
|
||||||
message: 'successful render',
|
message: addDateToLog(data.result),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -75,7 +75,7 @@ export const render = async ({ code, settings }) => {
|
|||||||
status: 'error',
|
status: 'error',
|
||||||
message: {
|
message: {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: 'network issue',
|
message: addDateToLog('network issue'),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,3 +87,8 @@ const openScad = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default openScad
|
export default openScad
|
||||||
|
|
||||||
|
function addDateToLog(message) {
|
||||||
|
return `-> ${new Date().toLocaleString()}
|
||||||
|
${message}`
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user