export html file both from web page and electron

This commit is contained in:
Jan Prochazka
2021-11-11 14:33:36 +01:00
parent b9da035a97
commit d2299ab926
7 changed files with 113 additions and 26 deletions

View File

@@ -117,20 +117,29 @@ module.exports = {
return res;
},
exportChart_meta: 'post',
async exportChart({ title, config, image }) {
generateUploadsFile_meta: 'get',
async generateUploadsFile() {
const fileName = `${uuidv1()}.html`;
return {
fileName,
filePath: path.join(uploadsdir(), fileName),
};
},
exportChart_meta: 'post',
async exportChart({ filePath, title, config, image }) {
const fileName = path.parse(filePath).base;
const imageFile = `${fileName}.png`;
const html = getChartExport(title, config, imageFile);
await fs.writeFile(path.join(uploadsdir(), fileName), html);
await fs.writeFile(filePath, 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);
await fs.writeFile(filePath + '.png', buf);
}
}
return fileName;
return true;
},
};