Fetch food photos from ordering platform after menu extraction
- Pass platform URLs from discovery to extraction phase - Call platform_images mode with stealth Playwright - Fuzzy match platform images to extracted items by name - Show progress during image fetching Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
baf0d5dfc9
commit
2d1618dc1c
1 changed files with 41 additions and 1 deletions
|
|
@ -1428,8 +1428,9 @@
|
|||
const menuPages = discoverResult.menuPages || [];
|
||||
const siteName = discoverResult.siteName || '';
|
||||
|
||||
// Store business info from discovery (JSON-LD, meta tags, etc.)
|
||||
// Store business info and platform URLs from discovery
|
||||
config.discoveredBusinessInfo = discoverResult.businessInfo || {};
|
||||
config.platformPages = discoverResult.platformPages || [];
|
||||
|
||||
if (menuPages.length > 1) {
|
||||
// Multiple menus found — show confirmation step
|
||||
|
|
@ -1572,6 +1573,43 @@
|
|||
.join('; ');
|
||||
}
|
||||
|
||||
// Fetch images from ordering platform (stealth Playwright)
|
||||
const platformUrl = (config.platformPages || [])[0] || '';
|
||||
let platformImageMap = {};
|
||||
if (platformUrl && allItems.length > 0) {
|
||||
document.getElementById('conversation').innerHTML = '';
|
||||
addMessage('ai', `
|
||||
<div style="display:flex;align-items:center;gap:12px;">
|
||||
<div class="loading-spinner"></div>
|
||||
<span>Grabbing food photos from ordering platform...</span>
|
||||
</div>
|
||||
`);
|
||||
|
||||
try {
|
||||
const imgResp = await fetch(`${config.apiBaseUrl}/setup/analyzeMenuUrl.php`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ mode: 'platform_images', url: platformUrl, items: allItems.map(i => i.name) })
|
||||
});
|
||||
const imgResult = await imgResp.json();
|
||||
if (imgResult.OK && imgResult.imageMap) {
|
||||
platformImageMap = imgResult.imageMap;
|
||||
const matchCount = Object.keys(platformImageMap).length;
|
||||
// Match images to items by name
|
||||
let matched = 0;
|
||||
allItems.forEach(item => {
|
||||
if (platformImageMap[item.name]) {
|
||||
item.imageUrl = platformImageMap[item.name];
|
||||
matched++;
|
||||
}
|
||||
});
|
||||
console.log(`Platform images: ${matchCount} found, ${matched} matched to items`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Platform image fetch error:', err);
|
||||
}
|
||||
}
|
||||
|
||||
// Build final combined data
|
||||
document.getElementById('conversation').innerHTML = '';
|
||||
config.extractedData = {
|
||||
|
|
@ -1589,9 +1627,11 @@
|
|||
|
||||
const totalItems = allItems.length;
|
||||
const totalCats = allCategories.length;
|
||||
const imgCount = allItems.filter(i => i.imageUrl).length;
|
||||
const schedSummary = allMenus.filter(m => m.schedule).map(m => `${m.name}: ${m.schedule}`).join(', ');
|
||||
addMessage('ai', `
|
||||
<p>Done! Found <strong>${totalItems} items</strong> across <strong>${totalCats} categories</strong> in <strong>${allMenus.length} menus</strong>.</p>
|
||||
${imgCount ? `<p style="font-size:13px;color:var(--gray-500);">${imgCount} item images found</p>` : ''}
|
||||
${schedSummary ? `<p style="font-size:13px;color:var(--gray-500);">${schedSummary}</p>` : ''}
|
||||
`);
|
||||
|
||||
|
|
|
|||
Reference in a new issue