feat(app): configure and safely switch multi-address servers
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import '../session/server_session.dart';
|
||||
|
||||
/// Probe only the selected profile's explicit aliases, with a bounded wait.
|
||||
/// Never send a mutation or discover/switch logical servers.
|
||||
Future<({Uri endpoint, SessionState state})> probeServerAddresses(
|
||||
List<Uri> addresses, {
|
||||
required Future<SessionState> Function(Uri) check,
|
||||
required bool Function() isCurrent,
|
||||
}) async {
|
||||
if (addresses.isEmpty) throw ArgumentError('No server addresses to probe.');
|
||||
for (final endpoint in addresses) {
|
||||
if (!isCurrent()) break;
|
||||
final state = await check(endpoint).timeout(
|
||||
const Duration(seconds: 5),
|
||||
onTimeout: () => SessionState.unreachable,
|
||||
);
|
||||
if (!isCurrent()) break;
|
||||
if (state != SessionState.unreachable) {
|
||||
return (endpoint: endpoint, state: state);
|
||||
}
|
||||
}
|
||||
return (endpoint: addresses.first, state: SessionState.unreachable);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import '../api_gateway.dart';
|
||||
|
||||
final _identities = Expando<String>('logical server identity');
|
||||
|
||||
/// Aliases share an identity; switching profiles creates a fresh app/gateway.
|
||||
void bindServerIdentity(ApiGateway gateway, String? id) {
|
||||
_identities[gateway] = id;
|
||||
}
|
||||
|
||||
String? serverIdentity(ApiGateway gateway) => _identities[gateway];
|
||||
|
||||
/// Existing local data belongs only to the migrated original server.
|
||||
String serverStorageScope(String? id) =>
|
||||
id == null || id == 'legacy-server' ? '' : id;
|
||||
|
||||
String scopedServerKey(String key, String scope) =>
|
||||
scope.isEmpty ? key : '$key.server.${Uri.encodeComponent(scope)}';
|
||||
@@ -22,6 +22,14 @@ class ServerSession {
|
||||
|
||||
static String? get serverId => _serverId;
|
||||
|
||||
/// Drop the active trust selection without deleting any server's sign-in.
|
||||
static void clearSelection() {
|
||||
_generation++;
|
||||
_serverId = null;
|
||||
_origins = {};
|
||||
cookie = null;
|
||||
}
|
||||
|
||||
static String _scopeKey(String id) =>
|
||||
'pipelines.session.v2.${Uri.encodeComponent(id)}.cookie';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user