fix: incorrect evaluation of js
This commit is contained in:
parent
e41e81d162
commit
59db3976fe
@ -15,6 +15,12 @@ const exec = promisify(execSync)
|
|||||||
|
|
||||||
let tmpDir: string
|
let tmpDir: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* body is the stl
|
||||||
|
* query
|
||||||
|
* price: algorithm from settings
|
||||||
|
* adionnal settings from https://manual.slic3r.org/advanced/command-line
|
||||||
|
*/
|
||||||
export const post: APIRoute = async ({ request }) => {
|
export const post: APIRoute = async ({ request }) => {
|
||||||
if (!tmpDir) {
|
if (!tmpDir) {
|
||||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'paas-'))
|
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'paas-'))
|
||||||
@ -121,9 +127,9 @@ export const post: APIRoute = async ({ request }) => {
|
|||||||
await fs.rm(stlPath)
|
await fs.rm(stlPath)
|
||||||
await fs.rm(gcodePath)
|
await fs.rm(gcodePath)
|
||||||
const params = getParams(gcode)
|
const params = getParams(gcode)
|
||||||
let price = -1
|
let price: string | undefined
|
||||||
if (query?.algo) {
|
if (query?.algo) {
|
||||||
let algo = query.algo as string
|
let algo = decodeURI(query.algo as string)
|
||||||
// objectLoop(params, (value, key) => {
|
// objectLoop(params, (value, key) => {
|
||||||
// if (typeof value !== 'number') {
|
// if (typeof value !== 'number') {
|
||||||
// return
|
// return
|
||||||
@ -132,13 +138,39 @@ export const post: APIRoute = async ({ request }) => {
|
|||||||
// algo = algo.replace(key, value.toString())
|
// algo = algo.replace(key, value.toString())
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
price = evaluate(algo, params)
|
try {
|
||||||
|
const tmp = evaluate(algo, params)
|
||||||
|
if (typeof tmp === 'number') {
|
||||||
|
price = tmp.toFixed(2)
|
||||||
|
} else {
|
||||||
|
return buildRFC7807Error({
|
||||||
|
type: '/algorithm-error',
|
||||||
|
status: 500,
|
||||||
|
title: 'Algorithm compilation error',
|
||||||
|
details: 'It seems the algorithm resolution failed',
|
||||||
|
algorithm: algo,
|
||||||
|
algorithmError: 'Algorithm return a Unit',
|
||||||
|
parameters: params
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.dir(e)
|
||||||
|
return buildRFC7807Error({
|
||||||
|
type: '/algorithm-error',
|
||||||
|
status: 500,
|
||||||
|
title: 'Algorithm compilation error',
|
||||||
|
details: 'It seems the algorithm resolution failed',
|
||||||
|
algorithm: algo,
|
||||||
|
algorithmError: e,
|
||||||
|
parameters: params
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.log('request successfull :)', file)
|
console.log('request successfull :)', file)
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
price: parseFloat(price.toFixed(2)),
|
price: price ? parseFloat(price) : undefined,
|
||||||
...getParams(gcode),
|
...getParams(gcode),
|
||||||
gcode
|
gcode
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user