fix(all): Fix in AS IMAGE generation of single row.

This commit is contained in:
Rodrigo Rodriguez 2023-07-23 16:37:21 -03:00
parent ad47305a02
commit ee6356d83b
2 changed files with 27 additions and 17 deletions

View file

@ -138,7 +138,7 @@
"open-docxtemplater-image-module": "1.0.3", "open-docxtemplater-image-module": "1.0.3",
"openai": "3.3.0", "openai": "3.3.0",
"pdf-extraction": "1.0.2", "pdf-extraction": "1.0.2",
"pdf-to-png-converter": "2.7.1", "pdf-to-png-converter": "3.1.0",
"pdfkit": "0.13.0", "pdfkit": "0.13.0",
"phone": "3.1.30", "phone": "3.1.30",
"pizzip": "3.1.3", "pizzip": "3.1.3",

View file

@ -51,7 +51,7 @@ import PizZip from 'pizzip';
import Docxtemplater from 'docxtemplater'; import Docxtemplater from 'docxtemplater';
import pptxTemplaterModule from 'pptxtemplater'; import pptxTemplaterModule from 'pptxtemplater';
import _ from 'lodash'; import _ from 'lodash';
// TODO: canvas error import { pdfToPng, PngPageOutput } from 'pdf-to-png-converter'; import { pdfToPng, PngPageOutput } from 'pdf-to-png-converter';
import sharp from 'sharp'; import sharp from 'sharp';
import ImageModule from 'open-docxtemplater-image-module'; import ImageModule from 'open-docxtemplater-image-module';
import DynamicsWebApi from 'dynamics-web-api'; import DynamicsWebApi from 'dynamics-web-api';
@ -182,12 +182,25 @@ export class SystemKeywords {
if (Array.isArray(data)) { if (Array.isArray(data)) {
isObject = Object.keys(data[1]) !== null; isObject = Object.keys(data[1]) !== null;
} }
else {
isObject = true;
}
if (isObject || JSON.parse(data) !== null) { if (isObject || JSON.parse(data) !== null) {
let keys = Object.keys(data[1]);
// Copies data from JSON format into simple array.
if (!Array.isArray(data)) {
// If data is a single object, wrap it in an array
data = [data];
}
// Ensure that keys is an array of strings representing the object keys
const keys = Object.keys(data[0]);
if (headers) { if (headers) {
output[0] = []; output[0] = [];
// Copies headers as the first element. // Copies headers as the first element.
for (let i = 0; i < keys.length; i++) { for (let i = 0; i < keys.length; i++) {
@ -197,7 +210,6 @@ export class SystemKeywords {
output.push({ gbarray: '0' }); output.push({ gbarray: '0' });
} }
// Copies data from JSON format into simple array.
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
output[i + 1] = []; output[i + 1] = [];
@ -205,7 +217,6 @@ export class SystemKeywords {
output[i + 1][j] = data[i][keys[j]]; output[i + 1][j] = data[i][keys[j]];
} }
} }
return output; return output;
} }
} catch (error) { } catch (error) {
@ -217,14 +228,14 @@ export class SystemKeywords {
/** /**
* *
* @param data * @param data
* @param renderPDF
* @param renderImage * @param renderImage
* @returns * @returns
* *
* @see http://tabulator.info/examples/5.2 * @see http://tabulator.info/examples/5.2
*/ */
private async renderTable(pid, data, renderPDF, renderImage) { private async renderTable(pid, data, renderPDF, renderImage) {
if (!data[1]) {
if (data.length && !data[1]) {
return null; return null;
} }
@ -350,16 +361,14 @@ export class SystemKeywords {
// Converts the PDF to PNG. // Converts the PDF to PNG.
const pngPages /*: PngPageOutput*/ = []; const pngPages: PngPageOutput[] = await pdfToPng(gbfile.data, {
// TODO: https://github.com/GeneralBots/BotServer/issues/350 disableFontFace: false,
// await pdfToPng(gbfile.data, { useSystemFonts: false,
// disableFontFace: false, viewportScale: 2.0,
// useSystemFonts: false, pagesToProcess: [1],
// viewportScale: 2.0, strictPagesToProcess: false,
// pagesToProcess: [1], verbosityLevel: 0
// strictPagesToProcess: false, });
// verbosityLevel: 0
// });
// Prepare an image on cache and return the GBFILE information. // Prepare an image on cache and return the GBFILE information.
@ -1867,3 +1876,4 @@ export class SystemKeywords {
GBLog.info(`Twitter Automation: ${text}.`); GBLog.info(`Twitter Automation: ${text}.`);
} }
} }