feat: enhance bottle metadata with distillation/bottling dates and batch info

This commit is contained in:
2025-12-18 13:24:41 +01:00
parent 61a7966579
commit acf02a78dd
7 changed files with 81 additions and 8 deletions

View File

@@ -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

View File

@@ -55,6 +55,9 @@ export async function saveBottle(
status: 'sealed', // Default status
is_whisky: metadata.is_whisky ?? true,
confidence: metadata.confidence ?? 100,
distilled_at: metadata.distilled_at,
bottled_at: metadata.bottled_at,
batch_info: metadata.batch_info,
})
.select()
.single();

View File

@@ -12,6 +12,9 @@ export async function updateBottle(bottleId: string, data: {
age?: number;
whiskybase_id?: string;
purchase_price?: number;
distilled_at?: string;
bottled_at?: string;
batch_info?: string;
}) {
const supabase = createServerActionClient({ cookies });
@@ -29,6 +32,9 @@ export async function updateBottle(bottleId: string, data: {
age: data.age,
whiskybase_id: data.whiskybase_id,
purchase_price: data.purchase_price,
distilled_at: data.distilled_at,
bottled_at: data.bottled_at,
batch_info: data.batch_info,
updated_at: new Date().toISOString(),
})
.eq('id', bottleId)