aves_mio1/lib/remote/remote_http.dart
FabioMich66 507c131502
Some checks are pending
Quality check / Flutter analysis (push) Waiting to run
Quality check / CodeQL analysis (java-kotlin) (push) Waiting to run
ok2
2026-03-07 23:53:27 +01:00

26 lines
No EOL
870 B
Dart

// lib/remote/remote_http.dart
import 'remote_settings.dart';
import 'auth_client.dart';
class RemoteHttp {
static RemoteAuth? _auth;
static String? _base;
static Future<void> init() async {
final s = await RemoteSettings.load();
_base = s.baseUrl.trim().isEmpty ? null : s.baseUrl.trim();
_auth = RemoteAuth(baseUrl: s.baseUrl, email: s.email, password: s.password);
}
static Future<Map<String, String>> headers() async {
if (_auth == null) await init();
return await _auth!.authHeaders(); // login on-demand
}
static String absUrl(String? relativePath) {
if (_base == null || _base!.isEmpty || relativePath == null || relativePath.isEmpty) return '';
final b = _base!.endsWith('/') ? _base! : '${_base!}/';
final rel = relativePath.startsWith('/') ? relativePath.substring(1) : relativePath;
return '$b$rel';
}
}