26 lines
No EOL
870 B
Dart
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';
|
|
}
|
|
} |