Phase 7 - Added Firebase layer
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import '../data/firebase/models/firebase_config.dart';
|
||||
|
||||
/// Configuration class that holds application settings.
|
||||
///
|
||||
/// This class contains environment-specific configuration values
|
||||
/// such as API base URL, Immich settings, and logging settings.
|
||||
/// such as API base URL, Immich settings, logging settings, and Firebase configuration.
|
||||
class AppConfig {
|
||||
/// The base URL for API requests.
|
||||
final String apiBaseUrl;
|
||||
@@ -18,6 +20,9 @@ class AppConfig {
|
||||
/// List of Nostr relay URLs for testing and production.
|
||||
final List<String> nostrRelays;
|
||||
|
||||
/// Firebase configuration for this environment.
|
||||
final FirebaseConfig firebaseConfig;
|
||||
|
||||
/// Creates an [AppConfig] instance with the provided values.
|
||||
///
|
||||
/// [apiBaseUrl] - The base URL for API requests.
|
||||
@@ -25,18 +30,21 @@ class AppConfig {
|
||||
/// [immichBaseUrl] - Immich server base URL.
|
||||
/// [immichApiKey] - Immich API key for authentication.
|
||||
/// [nostrRelays] - List of Nostr relay URLs (e.g., ['wss://relay.example.com']).
|
||||
/// [firebaseConfig] - Firebase configuration for this environment.
|
||||
const AppConfig({
|
||||
required this.apiBaseUrl,
|
||||
required this.enableLogging,
|
||||
required this.immichBaseUrl,
|
||||
required this.immichApiKey,
|
||||
required this.nostrRelays,
|
||||
required this.firebaseConfig,
|
||||
});
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AppConfig(apiBaseUrl: $apiBaseUrl, enableLogging: $enableLogging, '
|
||||
'immichBaseUrl: $immichBaseUrl, nostrRelays: ${nostrRelays.length})';
|
||||
'immichBaseUrl: $immichBaseUrl, nostrRelays: ${nostrRelays.length}, '
|
||||
'firebaseConfig: $firebaseConfig)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -47,7 +55,13 @@ class AppConfig {
|
||||
other.enableLogging == enableLogging &&
|
||||
other.immichBaseUrl == immichBaseUrl &&
|
||||
other.immichApiKey == immichApiKey &&
|
||||
other.nostrRelays.toString() == nostrRelays.toString();
|
||||
other.nostrRelays.toString() == nostrRelays.toString() &&
|
||||
other.firebaseConfig.enabled == firebaseConfig.enabled &&
|
||||
other.firebaseConfig.firestoreEnabled == firebaseConfig.firestoreEnabled &&
|
||||
other.firebaseConfig.storageEnabled == firebaseConfig.storageEnabled &&
|
||||
other.firebaseConfig.authEnabled == firebaseConfig.authEnabled &&
|
||||
other.firebaseConfig.messagingEnabled == firebaseConfig.messagingEnabled &&
|
||||
other.firebaseConfig.analyticsEnabled == firebaseConfig.analyticsEnabled;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -56,6 +70,12 @@ class AppConfig {
|
||||
enableLogging.hashCode ^
|
||||
immichBaseUrl.hashCode ^
|
||||
immichApiKey.hashCode ^
|
||||
nostrRelays.hashCode;
|
||||
nostrRelays.hashCode ^
|
||||
firebaseConfig.enabled.hashCode ^
|
||||
firebaseConfig.firestoreEnabled.hashCode ^
|
||||
firebaseConfig.storageEnabled.hashCode ^
|
||||
firebaseConfig.authEnabled.hashCode ^
|
||||
firebaseConfig.messagingEnabled.hashCode ^
|
||||
firebaseConfig.analyticsEnabled.hashCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'app_config.dart';
|
||||
import '../data/firebase/models/firebase_config.dart';
|
||||
|
||||
/// Exception thrown when an invalid environment is provided to [ConfigLoader].
|
||||
class InvalidEnvironmentException implements Exception {
|
||||
@@ -72,6 +73,18 @@ class ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to create FirebaseConfig from environment variables
|
||||
FirebaseConfig createFirebaseConfig() {
|
||||
return FirebaseConfig(
|
||||
enabled: getBoolEnv('FIREBASE_ENABLED', false),
|
||||
firestoreEnabled: getBoolEnv('FIREBASE_FIRESTORE_ENABLED', true),
|
||||
storageEnabled: getBoolEnv('FIREBASE_STORAGE_ENABLED', true),
|
||||
authEnabled: getBoolEnv('FIREBASE_AUTH_ENABLED', true),
|
||||
messagingEnabled: getBoolEnv('FIREBASE_MESSAGING_ENABLED', true),
|
||||
analyticsEnabled: getBoolEnv('FIREBASE_ANALYTICS_ENABLED', true),
|
||||
);
|
||||
}
|
||||
|
||||
switch (env) {
|
||||
case 'dev':
|
||||
return AppConfig(
|
||||
@@ -83,6 +96,7 @@ class ConfigLoader {
|
||||
'wss://nostrum.satoshinakamoto.win',
|
||||
'wss://nos.lol',
|
||||
]),
|
||||
firebaseConfig: createFirebaseConfig(),
|
||||
);
|
||||
case 'prod':
|
||||
return AppConfig(
|
||||
@@ -93,6 +107,7 @@ class ConfigLoader {
|
||||
nostrRelays: getListEnv('NOSTR_RELAYS_PROD', [
|
||||
'wss://relay.damus.io',
|
||||
]),
|
||||
firebaseConfig: createFirebaseConfig(),
|
||||
);
|
||||
default:
|
||||
throw InvalidEnvironmentException(environment);
|
||||
|
||||
Reference in New Issue
Block a user