Skip to content

Commit

Permalink
fix(all): Fix in AS IMAGE generation of single row.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jul 23, 2023
1 parent ad47305 commit ee6356d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"open-docxtemplater-image-module": "1.0.3",
"openai": "3.3.0",
"pdf-extraction": "1.0.2",
"pdf-to-png-converter": "2.7.1",
"pdf-to-png-converter": "3.1.0",
"pdfkit": "0.13.0",
"phone": "3.1.30",
"pizzip": "3.1.3",
Expand Down
42 changes: 26 additions & 16 deletions packages/basic.gblib/services/SystemKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import PizZip from 'pizzip';
import Docxtemplater from 'docxtemplater';
import pptxTemplaterModule from 'pptxtemplater';
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 ImageModule from 'open-docxtemplater-image-module';
import DynamicsWebApi from 'dynamics-web-api';
Expand Down Expand Up @@ -182,12 +182,25 @@ export class SystemKeywords {
if (Array.isArray(data)) {
isObject = Object.keys(data[1]) !== null;
}
else {
isObject = true;
}

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) {
output[0] = [];

// Copies headers as the first element.

for (let i = 0; i < keys.length; i++) {
Expand All @@ -197,15 +210,13 @@ export class SystemKeywords {
output.push({ gbarray: '0' });
}

// Copies data from JSON format into simple array.

for (let i = 0; i < data.length; i++) {
output[i + 1] = [];
for (let j = 0; j < keys.length; j++) {
output[i + 1][j] = data[i][keys[j]];
}
}

return output;
}
} catch (error) {
Expand All @@ -217,14 +228,14 @@ export class SystemKeywords {
/**
*
* @param data
* @param renderPDF
* @param renderImage
* @returns
*
* @see http://tabulator.info/examples/5.2
*/
private async renderTable(pid, data, renderPDF, renderImage) {
if (!data[1]) {

if (data.length && !data[1]) {
return null;
}

Expand Down Expand Up @@ -350,16 +361,14 @@ export class SystemKeywords {

// Converts the PDF to PNG.

const pngPages /*: PngPageOutput*/ = [];
// TODO: https://github.com/GeneralBots/BotServer/issues/350
// await pdfToPng(gbfile.data, {
// disableFontFace: false,
// useSystemFonts: false,
// viewportScale: 2.0,
// pagesToProcess: [1],
// strictPagesToProcess: false,
// verbosityLevel: 0
// });
const pngPages: PngPageOutput[] = await pdfToPng(gbfile.data, {
disableFontFace: false,
useSystemFonts: false,
viewportScale: 2.0,
pagesToProcess: [1],
strictPagesToProcess: false,
verbosityLevel: 0
});

// Prepare an image on cache and return the GBFILE information.

Expand Down Expand Up @@ -1867,3 +1876,4 @@ export class SystemKeywords {
GBLog.info(`Twitter Automation: ${text}.`);
}
}

0 comments on commit ee6356d

Please sign in to comment.