fix(llm.gblib): Fix in doc. publishing.

This commit is contained in:
Rodrigo Rodriguez 2024-12-09 08:07:34 -03:00
parent 619d094886
commit 93c6c51f3a
3 changed files with 61 additions and 33 deletions

View file

@ -237,6 +237,7 @@
"walk-promise": "0.2.0", "walk-promise": "0.2.0",
"washyourmouthoutwithsoap": "1.0.2", "washyourmouthoutwithsoap": "1.0.2",
"webdav-server": "2.6.2", "webdav-server": "2.6.2",
"webp-converter": "^2.3.3",
"whatsapp-cloud-api": "0.3.1", "whatsapp-cloud-api": "0.3.1",
"whatsapp-web.js": "1.26.1-alpha.1", "whatsapp-web.js": "1.26.1-alpha.1",
"winston": "3.14.2", "winston": "3.14.2",

View file

@ -780,10 +780,19 @@ export class SystemKeywords {
}); });
GBLogEx.info(min, `SAVE '${table}': ${rows.length} row(s).`); GBLogEx.info(min, `SAVE '${table}': ${rows.length} row(s).`);
// Capture the values we need for retries
const tableName = table;
const minRef = min;
await retry( await retry(
async bail => { async (bail) => {
await t.bulkCreate(rowsDest); const t = this.getTableFromName(tableName, minRef);
rowsDest = null; try {
await t.bulkCreate(rowsDest);
rowsDest = null;
} catch (error) {
throw error;
}
}, },
{ {
retries: 5, retries: 5,
@ -1690,7 +1699,7 @@ export class SystemKeywords {
const dstPath = urlJoin(packagePath, dest); const dstPath = urlJoin(packagePath, dest);
if (path.extname(srcPath) === 'ai'){ if (path.extname(srcPath) === 'ai') {
// TODO: To be done. // TODO: To be done.
@ -1733,7 +1742,7 @@ export class SystemKeywords {
} }
throw error; throw error;
} }
} }
} }
/** /**
@ -2900,27 +2909,27 @@ export class SystemKeywords {
public async convertAI2HTML(aiFilePath) { public async convertAI2HTML(aiFilePath) {
// Convert the AI file to HTML and assets // Convert the AI file to HTML and assets
const result = await ai2html.convertFile(aiFilePath, { const result = await ai2html.convertFile(aiFilePath, {
outputFormat: 'html', outputFormat: 'html',
outputWriteMethod: 'write-file', outputWriteMethod: 'write-file',
outputPath: path.dirname(aiFilePath), outputPath: path.dirname(aiFilePath),
useDocumentSettings: true, useDocumentSettings: true,
}); });
// Get the generated HTML file path // Get the generated HTML file path
const htmlFilePath = result.outputFiles.find((file) => file.endsWith('.html')).filePath; const htmlFilePath = result.outputFiles.find((file) => file.endsWith('.html')).filePath;
// Read the HTML content // Read the HTML content
const htmlContent = await fs.readFile(htmlFilePath, 'utf8'); const htmlContent = await fs.readFile(htmlFilePath, 'utf8');
// Save the HTML and assets to a cache directory // Save the HTML and assets to a cache directory
const cacheDir = path.join('work', 'cache'); const cacheDir = path.join('work', 'cache');
await fs.mkdir(cacheDir, { recursive: true }); await fs.mkdir(cacheDir, { recursive: true });
const cacheFilePath = path.join(cacheDir, path.basename(htmlFilePath)); const cacheFilePath = path.join(cacheDir, path.basename(htmlFilePath));
await fs.writeFile(cacheFilePath, htmlContent); await fs.writeFile(cacheFilePath, htmlContent);
return cacheFilePath; return cacheFilePath;
} }
@ -2997,7 +3006,7 @@ export class SystemKeywords {
}; };
// If the column is named 'id' or 'Id', set it as the primary key // If the column is named 'id' or 'Id', set it as the primary key
if (! pkAdded && (col.toLowerCase() === 'id' || col.toLowerCase() === 'internal_id')) { if (!pkAdded && (col.toLowerCase() === 'id' || col.toLowerCase() === 'internal_id')) {
schema[col].primaryKey = true; schema[col].primaryKey = true;
pkAdded = true; pkAdded = true;
} }
@ -3041,5 +3050,5 @@ export class SystemKeywords {
// Close SQLite connection // Close SQLite connection
await sqlite.close(); await sqlite.close();
} }
} }

View file

@ -73,6 +73,8 @@ import textract from 'textract';
import { GBUtil } from '../../../src/util.js'; import { GBUtil } from '../../../src/util.js';
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js'; import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js'; import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js';
import webp from 'webp-converter';
import os from 'os';
import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js'; import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
import { GBVMService } from '../../basic.gblib/services/GBVMService.js'; import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
import { GuaribasPackage } from '../../core.gbapp/models/GBModel.js'; import { GuaribasPackage } from '../../core.gbapp/models/GBModel.js';
@ -1080,6 +1082,18 @@ export class KBService implements IGBKBService {
throw new Error('Failed to parse ICO file'); throw new Error('Failed to parse ICO file');
} }
buffer = Buffer.from(images[0].buffer); buffer = Buffer.from(images[0].buffer);
} else if (buffer.slice(0, 4).toString('hex') === '52494646' &&
buffer.slice(8, 12).toString('hex') === '57454250') {
// Convert WebP to PNG using temporary files
const tempWebP = path.join(os.tmpdir(), `temp-${Date.now()}.webp`);
const tempPNG = path.join(os.tmpdir(), `temp-${Date.now()}.png`);
await fs.writeFile(tempWebP, buffer);
await webp.dwebp(tempWebP, tempPNG, "-o");
buffer = await fs.readFile(tempPNG);
} else if (buffer.toString().includes('<svg')) { } else if (buffer.toString().includes('<svg')) {
// For SVG files, convert using svg2img // For SVG files, convert using svg2img
@ -1558,10 +1572,14 @@ export class KBService implements IGBKBService {
return filePath; // Return the saved file path return filePath; // Return the saved file path
} else { } else {
await page.goto(url, { await page.goto(url, {
waitUntil: 'networkidle2', waitUntil: 'domcontentloaded', // Changed to only wait for DOM
timeout: 60000 // Timeout after 1 minute (60,000 ms) timeout: 10000 // Reduced timeout to 10 seconds
}); });
// Stop all scripts and requests
await page.setRequestInterception(true);
page.on('request', request => request.abort());
const parsedUrl = new URL(url); const parsedUrl = new URL(url);