feat: implement plant identification result card component and initialize backend server infrastructure

This commit is contained in:
2026-04-08 22:13:36 +02:00
parent 09078c3c20
commit 8a9533c520
3 changed files with 22 additions and 16 deletions

View File

@@ -69,6 +69,14 @@ const SEMANTIC_SEARCH_COST = 2;
const HEALTH_CHECK_COST = 2;
const LOW_CONFIDENCE_REVIEW_THRESHOLD = 0.8;
let catalogCache = null;
const getCachedCatalogEntries = async (db) => {
if (catalogCache) return catalogCache;
catalogCache = await getPlants(db, { limit: 500 });
return catalogCache;
};
const DEFAULT_BOOTSTRAP_PLANTS = [
{
id: '1',
@@ -627,18 +635,16 @@ app.post('/v1/scan', async (request, response) => {
let modelUsed = null;
let modelFallbackCount = 0;
if (!isGuest(userId)) {
creditsCharged += await consumeCreditsWithIdempotency(
db,
userId,
chargeKey('scan-primary', userId, idempotencyKey),
SCAN_PRIMARY_COST,
);
}
const [creditResult, accountSnapshot, catalogEntries] = await Promise.all([
isGuest(userId)
? Promise.resolve(0)
: consumeCreditsWithIdempotency(db, userId, chargeKey('scan-primary', userId, idempotencyKey), SCAN_PRIMARY_COST),
getAccountSnapshot(db, userId),
getCachedCatalogEntries(db),
]);
creditsCharged += creditResult;
const accountSnapshot = await getAccountSnapshot(db, userId);
const scanPlan = accountSnapshot.plan === 'pro' ? 'pro' : 'free';
const catalogEntries = await getPlants(db, { limit: 500 });
let result = pickCatalogFallback(catalogEntries, imageUri, false, { silent: true });
let usedOpenAi = false;

View File

@@ -115,8 +115,8 @@ const applyCatalogGrounding = (aiResult, catalogEntries, language = 'en') => {
description: aiResult.description || matchedEntry.description || '',
careInfo: {
waterIntervalDays: Math.max(1, Number(matchedEntry.careInfo?.waterIntervalDays) || Number(aiResult.careInfo?.waterIntervalDays) || 7),
light: matchedEntry.careInfo?.light || aiResult.careInfo?.light || 'Unknown',
temp: matchedEntry.careInfo?.temp || aiResult.careInfo?.temp || 'Unknown',
light: (matchedEntry.careInfo?.light && matchedEntry.careInfo.light !== 'Unknown') ? matchedEntry.careInfo.light : (aiResult.careInfo?.light || 'Unknown'),
temp: (matchedEntry.careInfo?.temp && matchedEntry.careInfo.temp !== 'Unknown') ? matchedEntry.careInfo.temp : (aiResult.careInfo?.temp || 'Unknown'),
},
},
};