2026-06-28 19:03:44 -04:00
|
|
|
// src/storage/index.js — storage factory + SDK re-exports.
|
|
|
|
|
// STORAGE=firebase (default): adapter wraps SDK. STORAGE=ws: backend.
|
|
|
|
|
// App.js imports getStorage() for subscribe; still imports SDK pieces for writes (per-group refactor pending).
|
2026-06-28 17:51:39 -04:00
|
|
|
|
2026-06-28 19:03:44 -04:00
|
|
|
import { initializeApp } from 'firebase/app';
|
|
|
|
|
import {
|
2026-06-28 17:51:39 -04:00
|
|
|
getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken,
|
|
|
|
|
} from 'firebase/auth';
|
2026-06-28 19:03:44 -04:00
|
|
|
import {
|
2026-06-28 17:51:39 -04:00
|
|
|
getFirestore, doc, setDoc, getDoc, getDocs, addDoc, collection,
|
|
|
|
|
onSnapshot, updateDoc, deleteDoc, query, orderBy, limit, writeBatch,
|
|
|
|
|
} from 'firebase/firestore';
|
2026-06-28 19:03:44 -04:00
|
|
|
import { initFirebase, createFirebaseStorage } from './firebase';
|
2026-07-01 19:03:59 -04:00
|
|
|
import { createWsStorage } from './ws';
|
2026-06-28 19:03:44 -04:00
|
|
|
|
|
|
|
|
let storageInstance = null;
|
|
|
|
|
|
|
|
|
|
// Returns adapter instance implementing interface (getDoc/setDoc/subscribeDoc/etc).
|
|
|
|
|
export function getStorage() {
|
|
|
|
|
if (storageInstance) return storageInstance;
|
|
|
|
|
const mode = process.env.REACT_APP_STORAGE || 'firebase';
|
|
|
|
|
if (mode === 'firebase') {
|
|
|
|
|
const ok = initFirebase();
|
|
|
|
|
if (!ok) throw new Error('Firebase config missing. Check REACT_APP_FIREBASE_* env.');
|
|
|
|
|
storageInstance = createFirebaseStorage();
|
|
|
|
|
} else if (mode === 'ws') {
|
|
|
|
|
storageInstance = createWsStorage({
|
2026-07-01 19:03:59 -04:00
|
|
|
baseUrl: process.env.REACT_APP_BACKEND_URL || '',
|
|
|
|
|
wsUrl: process.env.REACT_APP_BACKEND_WS || '',
|
2026-06-28 19:03:44 -04:00
|
|
|
});
|
|
|
|
|
} else {
|
2026-07-04 12:22:04 -04:00
|
|
|
throw new Error(`Unknown REACT_APP_STORAGE mode: ${mode}. Use 'firebase' or 'ws'.`);
|
2026-06-28 19:03:44 -04:00
|
|
|
}
|
|
|
|
|
return storageInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getStorageMode() {
|
|
|
|
|
return process.env.REACT_APP_STORAGE || 'firebase';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export {
|
|
|
|
|
initializeApp,
|
|
|
|
|
getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken,
|
|
|
|
|
getFirestore, doc, setDoc, getDoc, getDocs, addDoc, collection,
|
|
|
|
|
onSnapshot, updateDoc, deleteDoc, query, orderBy, limit, writeBatch,
|
|
|
|
|
};
|