diff --git a/server/index.js b/server/index.js index f32ecda..2337531 100644 --- a/server/index.js +++ b/server/index.js @@ -10,7 +10,7 @@ dotenv.config({ path: path.join(__dirname, '.env.local'), override: true }); dotenv.config({ path: path.join(__dirname, '..', '.env') }); dotenv.config({ path: path.join(__dirname, '..', '.env.local') }); -const { closeDatabase, getDefaultDbPath, openDatabase } = require('./lib/sqlite'); +const { closeDatabase, getDefaultDbPath, openDatabase, get, run } = require('./lib/sqlite'); const { ensureAuthSchema, signUp: authSignUp, login: authLogin, issueToken, verifyJwt } = require('./lib/auth'); const { PlantImportValidationError, @@ -42,7 +42,11 @@ const { const app = express(); const port = Number(process.env.PORT || 3000); -const stripe = new Stripe((process.env.STRIPE_SECRET_KEY || '').trim() || 'sk_test_mock_key'); +const stripeSecretKey = (process.env.STRIPE_SECRET_KEY || '').trim(); +if (!stripeSecretKey) { + console.error('STRIPE_SECRET_KEY is not set. Payment endpoints will fail.'); +} +const stripe = new Stripe(stripeSecretKey || 'sk_test_placeholder_key_not_configured'); const resolveStripeModeFromKey = (key, livePrefix, testPrefix) => { const normalized = String(key || '').trim(); @@ -182,9 +186,15 @@ const pickCatalogFallback = (entries, imageUri, preferHighConfidence = false) => if (!Array.isArray(entries) || entries.length === 0) return null; const baseHash = hashString(`${imageUri || ''}|${entries.length}`); const index = baseHash % entries.length; + // Low confidence so the user knows this is a hash-based guess, not a real identification const confidence = preferHighConfidence - ? 0.84 + ((baseHash % 7) / 100) - : 0.62 + ((baseHash % 18) / 100); + ? 0.22 + ((baseHash % 3) / 100) + : 0.18 + ((baseHash % 7) / 100); + console.warn('Using hash-based catalog fallback — OpenAI is unavailable or returned null.', { + plant: entries[index]?.name, + confidence, + imageHint: (imageUri || '').slice(0, 80), + }); return toPlantResult(entries[index], confidence); }; @@ -836,8 +846,13 @@ const start = async () => { const stripeMode = getStripeSecretMode(); const stripePublishableMode = getStripePublishableMode(); - console.log(`Stripe mode: ${stripeMode}`); - console.log(`Stripe publishable mode: ${stripePublishableMode}`); + const maskKey = (key) => { + const k = String(key || '').trim(); + if (k.length < 12) return k ? '(too short to mask)' : '(not set)'; + return `${k.slice(0, 7)}...${k.slice(-4)}`; + }; + console.log(`Stripe Mode: ${stripeMode} | Secret: ${maskKey(process.env.STRIPE_SECRET_KEY)}`); + console.log(`Stripe Publishable Mode: ${stripePublishableMode} | Key: ${maskKey(process.env.STRIPE_PUBLISHABLE_KEY || process.env.EXPO_PUBLIC_STRIPE_PUBLISHABLE_KEY)}`); const server = app.listen(port, () => { console.log(`GreenLns server listening at http://localhost:${port}`);