diff --git a/packages/api/src/controllers/files.js b/packages/api/src/controllers/files.js index e78d2d432..bceed001b 100644 --- a/packages/api/src/controllers/files.js +++ b/packages/api/src/controllers/files.js @@ -118,10 +118,19 @@ module.exports = { }, exportChart_meta: 'post', - async exportChart({ title, config }) { - const html = getChartExport(title, config); + async exportChart({ title, config, image }) { const fileName = `${uuidv1()}.html`; + const imageFile = `${fileName}.png`; + const html = getChartExport(title, config, imageFile); await fs.writeFile(path.join(uploadsdir(), fileName), html); + if (image) { + const index = image.indexOf('base64,'); + if (index > 0) { + const data = image.substr(index + 'base64,'.length); + const buf = Buffer.from(data, 'base64'); + await fs.writeFile(path.join(uploadsdir(), imageFile), buf); + } + } return fileName; }, }; diff --git a/packages/api/src/utility/getChartExport.js b/packages/api/src/utility/getChartExport.js index 6ca69ae4b..cb278f5f9 100644 --- a/packages/api/src/utility/getChartExport.js +++ b/packages/api/src/utility/getChartExport.js @@ -1,4 +1,4 @@ -const getChartExport = (title, config) => { +const getChartExport = (title, config, imageFile) => { return ` @@ -25,7 +25,7 @@ const getChartExport = (title, config) => {
-
+