new(all): Auto import for logo, colors and website content.

This commit is contained in:
Rodrigo Rodriguez 2024-05-22 19:09:34 -03:00
parent 039805de05
commit 1e12c39acb

View file

@ -971,7 +971,7 @@ export class KBService implements IGBKBService {
for (const element of elements) { for (const element of elements) {
const src = await page.evaluate(el => el.getAttribute('src'), element); const src = await page.evaluate(el => el.getAttribute('src'), element);
if (src) { if (src) {
return src; return src.split('?')[0];
} }
} }
} }
@ -1029,23 +1029,25 @@ export class KBService implements IGBKBService {
let browser = await puppeteer.launch({ headless: false }); let browser = await puppeteer.launch({ headless: false });
const page = await this.getFreshPage(browser, website); const page = await this.getFreshPage(browser, website);
const logo = await this.getLogoByPage(page); let logo = await this.getLogoByPage(page);
path = DialogKeywords.getGBAIPath(min.botId); if (logo){
const logoPath = Path.join(process.env.PWD, 'work', path, 'cache'); path = DialogKeywords.getGBAIPath(min.botId);
const baseUrl = page.url().split('/').slice(0, 3).join('/'); const logoPath = Path.join(process.env.PWD, 'work', path, 'cache');
const logoBinary = await page.goto(urlJoin(baseUrl, logo)); const baseUrl = page.url().split('/').slice(0, 3).join('/');
const buffer = await logoBinary.buffer(); const logoBinary = await page.goto(urlJoin(baseUrl, logo));
const logoFilename = Path.basename(logo); const buffer = await logoBinary.buffer();
sharp(buffer) const logoFilename = Path.basename(logo);
.resize({ sharp(buffer)
width: 48, .resize({
height: 48, width: 48,
fit: 'inside', // Resize the image to fit within the specified dimensions height: 48,
withoutEnlargement: true // Don't enlarge the image if its dimensions are already smaller fit: 'inside', // Resize the image to fit within the specified dimensions
}) withoutEnlargement: true // Don't enlarge the image if its dimensions are already smaller
.toFile(Path.join(logoPath, logoFilename)); })
.toFile(Path.join(logoPath, logoFilename));
await min.core['setConfig'](min, 'Logo', logoFilename); await min.core['setConfig'](min, 'Logo', logoFilename);
}
// Extract dominant colors from the screenshot // Extract dominant colors from the screenshot