Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const renderHandler = async (req, res) => {
const { spaceId, dlvrToken, mgmtToken, devMode = false, hideFields = false } = req.body
if (!spaceId) {
return res.json({ error: 'Missing spaceId' })
}
if (!dlvrToken && !mgmtToken) {
return res.json({ error: 'Missing auth token' })
}
let contentTypes
try {
contentTypes = mgmtToken
? await convertApi.getContentTypesFromManagementApi(spaceId, mgmtToken)
: await convertApi.getContentTypesFromDistributionApi(spaceId, dlvrToken)
} catch (err) {
return res.json({ error: err })
}
const modelsMap = convertApi.contentTypesToModelMap(contentTypes);
const dotStr = convertApi.modelsMapToDot(modelsMap, {dev: devMode, hideEntityFields: hideFields});
const fileName = `${spaceId}-${Date.now()}`
if (dotStr && dotStr.length > 1) {
// wait for the png
await generateGraph(outFile(fileName, 'png'), dotStr, 'png')
// but those are fine to be finished later
setImmediate(() => generateGraph(outFile(fileName, 'svg'), dotStr, 'svg'))