fix(llm.gblib): Talk to data local db use fix.
This commit is contained in:
parent
173d473166
commit
9cebd81a37
1 changed files with 24 additions and 18 deletions
|
@ -1571,6 +1571,15 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
return filePath; // Return the saved file path
|
return filePath; // Return the saved file path
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
// Get the last part of the URL path or default to 'index' if empty
|
||||||
|
const pathParts = parsedUrl.pathname.split('/').filter(Boolean); // Remove empty parts
|
||||||
|
const lastPath = pathParts.length > 0 ? pathParts[pathParts.length - 1] : 'index';
|
||||||
|
const flatLastPath = lastPath.replace(/\W+/g, '-'); // Flatten the last part of the path
|
||||||
|
|
||||||
|
const fileName = `${flatLastPath}.html`;
|
||||||
|
const filePath = path.join(directoryPath, fileName);
|
||||||
|
|
||||||
// Configure request interception before navigation
|
// Configure request interception before navigation
|
||||||
await page.setRequestInterception(true);
|
await page.setRequestInterception(true);
|
||||||
page.on('request', request => {
|
page.on('request', request => {
|
||||||
|
@ -1583,21 +1592,18 @@ export class KBService implements IGBKBService {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Navigate with strict timeout and wait for content
|
// Navigate with strict timeout and wait for content
|
||||||
await page.goto(url, {
|
// Navigate and get content even if page fails to load fully
|
||||||
waitUntil: 'networkidle0', // Wait until network is idle
|
let content = '';
|
||||||
timeout: 30000 // 30 second timeout
|
try {
|
||||||
});
|
await page.goto(url, {
|
||||||
|
waitUntil: 'networkidle0', // Wait until network is idle
|
||||||
const parsedUrl = new URL(url);
|
timeout: 30000 // 30 second timeout
|
||||||
|
});
|
||||||
// Get the last part of the URL path or default to 'index' if empty
|
} catch (err) {
|
||||||
const pathParts = parsedUrl.pathname.split('/').filter(Boolean); // Remove empty parts
|
// Ignore timeout/navigation errors
|
||||||
const lastPath = pathParts.length > 0 ? pathParts[pathParts.length - 1] : 'index';
|
}
|
||||||
const flatLastPath = lastPath.replace(/\W+/g, '-'); // Flatten the last part of the path
|
|
||||||
|
|
||||||
const fileName = `${flatLastPath}.html`;
|
|
||||||
const filePath = path.join(directoryPath, fileName);
|
|
||||||
|
|
||||||
|
// Get whatever HTML content was loaded
|
||||||
const htmlContent = await page.content();
|
const htmlContent = await page.content();
|
||||||
|
|
||||||
// Convert HTML to Markdown using html2md
|
// Convert HTML to Markdown using html2md
|
||||||
|
|
Loading…
Add table
Reference in a new issue