mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 01:06:44 +00:00
fix(recovery): Implement server type id requesting on recovery finish
This commit is contained in:
parent
51f5bb9f31
commit
80f28463ec
|
@ -721,12 +721,15 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
await repository.saveIsServerResetedSecondTime(true);
|
||||
await repository.saveHasFinalChecked(true);
|
||||
await repository.saveIsRecoveringServer(false);
|
||||
final serverInfo = await ProvidersController.currentServerProvider!
|
||||
.getServerInfo(state.serverDetails!.id);
|
||||
final User mainUser = await repository.getMainUser();
|
||||
await repository.saveRootUser(mainUser);
|
||||
final ServerInstallationRecovery updatedState =
|
||||
(state as ServerInstallationRecovery).copyWith(
|
||||
backblazeCredential: backblazeCredential,
|
||||
rootUser: mainUser,
|
||||
serverTypeIdentificator: serverInfo.data?.serverTypeId ?? '',
|
||||
);
|
||||
emit(updatedState.finish());
|
||||
}
|
||||
|
|
|
@ -3,12 +3,14 @@ class ServerBasicInfo {
|
|||
required this.id,
|
||||
required this.name,
|
||||
required this.reverseDns,
|
||||
required this.serverTypeId,
|
||||
required this.ip,
|
||||
required this.created,
|
||||
});
|
||||
final int id;
|
||||
final String name;
|
||||
final String reverseDns;
|
||||
final String serverTypeId;
|
||||
final String ip;
|
||||
final DateTime created;
|
||||
}
|
||||
|
@ -22,6 +24,7 @@ class ServerBasicInfoWithValidators extends ServerBasicInfo {
|
|||
id: serverBasicInfo.id,
|
||||
name: serverBasicInfo.name,
|
||||
reverseDns: serverBasicInfo.reverseDns,
|
||||
serverTypeId: serverBasicInfo.serverTypeId,
|
||||
ip: serverBasicInfo.ip,
|
||||
created: serverBasicInfo.created,
|
||||
isIpValid: isIpValid,
|
||||
|
@ -32,6 +35,7 @@ class ServerBasicInfoWithValidators extends ServerBasicInfo {
|
|||
required super.id,
|
||||
required super.name,
|
||||
required super.reverseDns,
|
||||
required super.serverTypeId,
|
||||
required super.ip,
|
||||
required super.created,
|
||||
required this.isIpValid,
|
||||
|
|
|
@ -81,6 +81,7 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
created: DateTime.now(),
|
||||
ip: ipv4,
|
||||
name: server['name'],
|
||||
serverTypeId: server['region']['slug'],
|
||||
);
|
||||
},
|
||||
).toList();
|
||||
|
@ -88,6 +89,57 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
return GenericResult(success: true, data: servers);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
||||
final int serverId,
|
||||
) async {
|
||||
ServerBasicInfo? server;
|
||||
final result = await _adapter.api().getServers();
|
||||
if (result.data.isEmpty || !result.success) {
|
||||
return GenericResult(
|
||||
success: result.success,
|
||||
data: server,
|
||||
code: result.code,
|
||||
message: result.message,
|
||||
);
|
||||
}
|
||||
|
||||
final rawServers = result.data;
|
||||
for (final rawServer in rawServers) {
|
||||
String? ipv4;
|
||||
if (rawServer['networks']['v4'].isNotEmpty) {
|
||||
for (final v4 in rawServer['networks']['v4']) {
|
||||
if (v4['type'].toString() == 'public') {
|
||||
ipv4 = v4['ip_address'].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
server = ServerBasicInfo(
|
||||
id: rawServer['id'],
|
||||
reverseDns: rawServer['name'],
|
||||
created: DateTime.now(),
|
||||
ip: ipv4!,
|
||||
name: rawServer['name'],
|
||||
serverTypeId: rawServer['region']['slug'],
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
return GenericResult(
|
||||
success: false,
|
||||
data: server,
|
||||
);
|
||||
}
|
||||
|
||||
return GenericResult(success: true, data: server);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
||||
final LaunchInstallationData installationData,
|
||||
|
|
|
@ -77,6 +77,7 @@ class HetznerServerProvider extends ServerProvider {
|
|||
ip: hetznerServer.publicNet.ipv4!.ip,
|
||||
reverseDns: hetznerServer.publicNet.ipv4!.reverseDns,
|
||||
created: hetznerServer.created,
|
||||
serverTypeId: hetznerServer.name,
|
||||
);
|
||||
} catch (e) {
|
||||
continue;
|
||||
|
@ -88,6 +89,53 @@ class HetznerServerProvider extends ServerProvider {
|
|||
return GenericResult(success: true, data: servers);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
||||
final int serverId,
|
||||
) async {
|
||||
ServerBasicInfo? server;
|
||||
final result = await _adapter.api().getServers();
|
||||
if (result.data.isEmpty || !result.success) {
|
||||
return GenericResult(
|
||||
success: result.success,
|
||||
data: server,
|
||||
code: result.code,
|
||||
message: result.message,
|
||||
);
|
||||
}
|
||||
|
||||
final List<HetznerServerInfo> hetznerServers = result.data;
|
||||
for (final hetznerServer in hetznerServers) {
|
||||
if (hetznerServer.publicNet.ipv4 == null ||
|
||||
hetznerServer.id != serverId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
server = ServerBasicInfo(
|
||||
id: hetznerServer.id,
|
||||
name: hetznerServer.name,
|
||||
ip: hetznerServer.publicNet.ipv4!.ip,
|
||||
reverseDns: hetznerServer.publicNet.ipv4!.reverseDns,
|
||||
created: hetznerServer.created,
|
||||
serverTypeId: hetznerServer.serverType.name,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
return GenericResult(
|
||||
success: false,
|
||||
data: server,
|
||||
);
|
||||
}
|
||||
|
||||
return GenericResult(success: true, data: server);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
||||
final LaunchInstallationData installationData,
|
||||
|
|
|
@ -24,6 +24,13 @@ abstract class ServerProvider {
|
|||
/// Only with public IPv4 addresses.
|
||||
Future<GenericResult<List<ServerBasicInfo>>> getServers();
|
||||
|
||||
/// Returns actual [ServerBasicInfo] of the
|
||||
/// requested server entry assigned
|
||||
/// to the authorized user.
|
||||
///
|
||||
/// Only with public IPv4 address.
|
||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(final int serverId);
|
||||
|
||||
/// Tries to launch installation of SelfPrivacy on
|
||||
/// the requested server entry for the authorized account.
|
||||
/// Depending on a server provider, the algorithm
|
||||
|
|
Loading…
Reference in a new issue