import admin from 'firebase-admin'; import fs from 'fs'; import path from 'path'; // Service Account file path - MUST be from transcript-master project const serviceAccountPath = path.resolve(process.cwd(), 'service-account.json'); try { if (!admin.apps.length) { // Explicitly using transcript-master project details const config = { databaseURL: "https://klingwatermark-default-rtdb.asia-southeast1.firebasedatabase.app", projectId: "klingwatermark" }; if (fs.existsSync(serviceAccountPath)) { const serviceAccount = JSON.parse(fs.readFileSync(serviceAccountPath, 'utf8')); // Safety check: ensure the file matches the database project if (serviceAccount.project_id !== "transcript-master") { console.error(`❌ CRITICAL: service-account.json is for project "${serviceAccount.project_id}", but database is "transcript-master". Please download the correct key.`); } config.credential = admin.credential.cert(serviceAccount); console.log("✅ Firebase Admin: Using service-account.json for transcript-master"); } else { console.warn("â„šī¸ Firebase Admin: service-account.json NOT FOUND. DB access will fail."); } admin.initializeApp(config); console.log("🚀 Firebase Admin Service Initialized for transcript-master"); } } catch (error) { console.error("❌ Firebase Init Error:", error.message); } export const db = admin.database();