feat: enhance bottle metadata with distillation/bottling dates and batch info
This commit is contained in:
@@ -9,6 +9,9 @@ export async function discoverWhiskybaseId(bottle: {
|
||||
distillery?: string;
|
||||
abv?: number;
|
||||
age?: number;
|
||||
distilled_at?: string;
|
||||
bottled_at?: string;
|
||||
batch_info?: string;
|
||||
}) {
|
||||
// Both Gemini and Custom Search often use the same API key if created via AI Studio
|
||||
const apiKey = process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY;
|
||||
@@ -24,24 +27,33 @@ export async function discoverWhiskybaseId(bottle: {
|
||||
try {
|
||||
// Construct targeted search query
|
||||
const queryParts = [
|
||||
`"${bottle.distillery || ''}"`,
|
||||
`"${bottle.name}"`,
|
||||
bottle.distillery ? `${bottle.distillery}` : '', // Removed quotes for more fuzzy matching
|
||||
bottle.name ? `${bottle.name}` : '',
|
||||
bottle.abv ? `${bottle.abv}%` : '',
|
||||
bottle.age ? `${bottle.age} year old` : ''
|
||||
bottle.age ? `${bottle.age} year old` : '',
|
||||
bottle.batch_info ? `"${bottle.batch_info}"` : '',
|
||||
bottle.distilled_at ? `distilled ${bottle.distilled_at}` : '',
|
||||
bottle.bottled_at ? `bottled ${bottle.bottled_at}` : ''
|
||||
].filter(Boolean);
|
||||
|
||||
const q = queryParts.join(' ');
|
||||
console.log('Whiskybase Search Query:', q);
|
||||
|
||||
const url = `https://www.googleapis.com/customsearch/v1?key=${apiKey}&cx=${cx}&q=${encodeURIComponent(q)}`;
|
||||
|
||||
const response = await fetch(url);
|
||||
const data = await response.json();
|
||||
|
||||
if (data.error) {
|
||||
console.error('Google API Error Response:', data.error);
|
||||
throw new Error(data.error.message || 'Google API Error');
|
||||
}
|
||||
|
||||
if (!data.items || data.items.length === 0) {
|
||||
return { success: false, error: 'Keine Treffer auf Whiskybase gefunden.' };
|
||||
return {
|
||||
success: false,
|
||||
error: `Keine Treffer auf Whiskybase gefunden. (Query: ${q})`
|
||||
};
|
||||
}
|
||||
|
||||
// Try to find the first result that looks like a valid product page
|
||||
|
||||
Reference in New Issue
Block a user