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

@@ -339,16 +339,15 @@ module.exports = {
},
generateDbDiffReport_meta: 'post',
async generateDbDiffReport({ sourceConid, sourceDatabase, targetConid, targetDatabase }) {
async generateDbDiffReport({ filePath, sourceConid, sourceDatabase, targetConid, targetDatabase }) {
const unifiedDiff = await this.getUnifiedDiff({ sourceConid, sourceDatabase, targetConid, targetDatabase });
const diffJson = parse(unifiedDiff);
// $: diffHtml = html(diffJson, { outputFormat: 'side-by-side', drawFileList: false });
const diffHtml = html(diffJson, { outputFormat: 'side-by-side' });
const fileName = `${uuidv1()}.html`;
await fs.writeFile(path.join(uploadsdir(), fileName), diff2htmlPage(diffHtml));
await fs.writeFile(filePath, diff2htmlPage(diffHtml));
return fileName;
return true;
},
};

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;
},
};