Phase 4 - synch engine complete
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'app_config.dart';
|
||||
|
||||
/// Exception thrown when an invalid environment is provided to [ConfigLoader].
|
||||
@@ -26,33 +27,72 @@ class ConfigLoader {
|
||||
|
||||
/// Loads configuration for the specified environment.
|
||||
///
|
||||
/// Reads from .env file if available, falls back to hardcoded defaults.
|
||||
///
|
||||
/// [environment] - The environment to load ('dev' or 'prod').
|
||||
///
|
||||
/// Returns an [AppConfig] instance for the specified environment.
|
||||
///
|
||||
/// Throws [InvalidEnvironmentException] if [environment] is not 'dev' or 'prod'.
|
||||
static AppConfig load(String environment) {
|
||||
switch (environment.toLowerCase()) {
|
||||
final env = environment.toLowerCase();
|
||||
|
||||
// Helper to get env var or fallback to default
|
||||
// Handles case where dotenv is not initialized (e.g., in tests)
|
||||
String getEnv(String key, String defaultValue) {
|
||||
try {
|
||||
return dotenv.env[key] ?? defaultValue;
|
||||
} catch (e) {
|
||||
// dotenv not initialized, use default
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to parse boolean from env
|
||||
bool getBoolEnv(String key, bool defaultValue) {
|
||||
try {
|
||||
final value = dotenv.env[key];
|
||||
if (value == null) return defaultValue;
|
||||
return value.toLowerCase() == 'true';
|
||||
} catch (e) {
|
||||
// dotenv not initialized, use default
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to parse comma-separated list from env
|
||||
List<String> getListEnv(String key, List<String> defaultValue) {
|
||||
try {
|
||||
final value = dotenv.env[key];
|
||||
if (value == null || value.isEmpty) return defaultValue;
|
||||
return value.split(',').map((s) => s.trim()).where((s) => s.isNotEmpty).toList();
|
||||
} catch (e) {
|
||||
// dotenv not initialized, use default
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
switch (env) {
|
||||
case 'dev':
|
||||
return const AppConfig(
|
||||
apiBaseUrl: 'https://api-dev.example.com',
|
||||
enableLogging: true,
|
||||
immichBaseUrl: 'https://photos.satoshinakamoto.win', // ← Change your Immich server URL here
|
||||
immichApiKey: '3v2fTujMJHy1T2rrVJVojdJS0ySm7IRcRvEcvvUvs0', // ← Change your Immich API key here
|
||||
nostrRelays: [ // ← Add Nostr relay URLs for testing
|
||||
return AppConfig(
|
||||
apiBaseUrl: getEnv('API_BASE_URL_DEV', 'https://api-dev.example.com'),
|
||||
enableLogging: getBoolEnv('ENABLE_LOGGING_DEV', true),
|
||||
immichBaseUrl: getEnv('IMMICH_BASE_URL', 'https://photos.satoshinakamoto.win'),
|
||||
immichApiKey: getEnv('IMMICH_API_KEY_DEV', 'your-dev-api-key-here'),
|
||||
nostrRelays: getListEnv('NOSTR_RELAYS_DEV', [
|
||||
'wss://nostrum.satoshinakamoto.win',
|
||||
'wss://nos.lol',
|
||||
],
|
||||
]),
|
||||
);
|
||||
case 'prod':
|
||||
return const AppConfig(
|
||||
apiBaseUrl: 'https://api.example.com',
|
||||
enableLogging: false,
|
||||
immichBaseUrl: 'https://photos.satoshinakamoto.win', // ← Change your Immich server URL here
|
||||
immichApiKey: 'your-prod-api-key-here', // ← Change your Immich API key here
|
||||
nostrRelays: [ // ← Add Nostr relay URLs for production
|
||||
return AppConfig(
|
||||
apiBaseUrl: getEnv('API_BASE_URL_PROD', 'https://api.example.com'),
|
||||
enableLogging: getBoolEnv('ENABLE_LOGGING_PROD', false),
|
||||
immichBaseUrl: getEnv('IMMICH_BASE_URL', 'https://photos.satoshinakamoto.win'),
|
||||
immichApiKey: getEnv('IMMICH_API_KEY_PROD', 'your-prod-api-key-here'),
|
||||
nostrRelays: getListEnv('NOSTR_RELAYS_PROD', [
|
||||
'wss://relay.damus.io',
|
||||
],
|
||||
]),
|
||||
);
|
||||
default:
|
||||
throw InvalidEnvironmentException(environment);
|
||||
|
||||
Reference in New Issue
Block a user