mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
Merge pull request 'fix(recovery): Implement server type id requesting on recovery finish' (#241) from servertype-id into master
Reviewed-on: https://git.selfprivacy.org/SelfPrivacy/selfprivacy.org.app/pulls/241 Reviewed-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
commit
c7b714cea5
|
@ -721,12 +721,18 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
await repository.saveIsServerResetedSecondTime(true);
|
await repository.saveIsServerResetedSecondTime(true);
|
||||||
await repository.saveHasFinalChecked(true);
|
await repository.saveHasFinalChecked(true);
|
||||||
await repository.saveIsRecoveringServer(false);
|
await repository.saveIsRecoveringServer(false);
|
||||||
|
final serverType = await ProvidersController.currentServerProvider!
|
||||||
|
.getServerType(state.serverDetails!.id);
|
||||||
|
await repository.saveServerType(serverType.data!);
|
||||||
|
await ProvidersController.currentServerProvider!
|
||||||
|
.trySetServerLocation(serverType.data!.location.identifier);
|
||||||
final User mainUser = await repository.getMainUser();
|
final User mainUser = await repository.getMainUser();
|
||||||
await repository.saveRootUser(mainUser);
|
await repository.saveRootUser(mainUser);
|
||||||
final ServerInstallationRecovery updatedState =
|
final ServerInstallationRecovery updatedState =
|
||||||
(state as ServerInstallationRecovery).copyWith(
|
(state as ServerInstallationRecovery).copyWith(
|
||||||
backblazeCredential: backblazeCredential,
|
backblazeCredential: backblazeCredential,
|
||||||
rootUser: mainUser,
|
rootUser: mainUser,
|
||||||
|
serverTypeIdentificator: serverType.data!.identifier,
|
||||||
);
|
);
|
||||||
emit(updatedState.finish());
|
emit(updatedState.finish());
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,93 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
return GenericResult(success: true, data: servers);
|
return GenericResult(success: true, data: servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<GenericResult<ServerType?>> getServerType(final int serverId) async {
|
||||||
|
ServerType? serverType;
|
||||||
|
dynamic server;
|
||||||
|
final result = await _adapter.api().getServers();
|
||||||
|
if (result.data.isEmpty || !result.success) {
|
||||||
|
return GenericResult(
|
||||||
|
success: result.success,
|
||||||
|
data: serverType,
|
||||||
|
code: result.code,
|
||||||
|
message: result.message,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List rawServers = result.data;
|
||||||
|
for (final rawServer in rawServers) {
|
||||||
|
if (rawServer['networks']['v4'].isNotEmpty) {
|
||||||
|
for (final v4 in rawServer['networks']['v4']) {
|
||||||
|
if (v4['type'].toString() == 'public') {
|
||||||
|
server = rawServer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
const String msg = 'getServerType: no server!';
|
||||||
|
print(msg);
|
||||||
|
return GenericResult(
|
||||||
|
success: false,
|
||||||
|
data: serverType,
|
||||||
|
message: msg,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final rawLocationsResult = await getAvailableLocations();
|
||||||
|
if (rawLocationsResult.data.isEmpty || !rawLocationsResult.success) {
|
||||||
|
return GenericResult(
|
||||||
|
success: rawLocationsResult.success,
|
||||||
|
data: serverType,
|
||||||
|
code: rawLocationsResult.code,
|
||||||
|
message: rawLocationsResult.message,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerProviderLocation? location;
|
||||||
|
for (final rawLocation in rawLocationsResult.data) {
|
||||||
|
if (rawLocation.identifier == server['region']['slug']) {
|
||||||
|
location = rawLocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
const String msg = 'getServerType: no location!';
|
||||||
|
print(msg);
|
||||||
|
return GenericResult(
|
||||||
|
success: false,
|
||||||
|
data: serverType,
|
||||||
|
message: msg,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerType? type;
|
||||||
|
final rawSize = DigitalOceanServerType.fromJson(server['size']);
|
||||||
|
for (final rawRegion in rawSize.regions) {
|
||||||
|
if (rawRegion == server['region']['slug']) {
|
||||||
|
type = ServerType(
|
||||||
|
title: rawSize.description,
|
||||||
|
identifier: rawSize.slug,
|
||||||
|
ram: rawSize.memory / 1024,
|
||||||
|
cores: rawSize.vcpus,
|
||||||
|
disk: DiskSize(byte: rawSize.disk * 1024 * 1024 * 1024),
|
||||||
|
price: Price(
|
||||||
|
value: rawSize.priceMonthly,
|
||||||
|
currency: currency,
|
||||||
|
),
|
||||||
|
location: location,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GenericResult(
|
||||||
|
success: true,
|
||||||
|
data: type,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
||||||
final LaunchInstallationData installationData,
|
final LaunchInstallationData installationData,
|
||||||
|
|
|
@ -88,6 +88,78 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
return GenericResult(success: true, data: servers);
|
return GenericResult(success: true, data: servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<GenericResult<ServerType?>> getServerType(final int serverId) async {
|
||||||
|
ServerType? serverType;
|
||||||
|
HetznerServerInfo? server;
|
||||||
|
final result = await _adapter.api().getServers();
|
||||||
|
if (result.data.isEmpty || !result.success) {
|
||||||
|
return GenericResult(
|
||||||
|
success: result.success,
|
||||||
|
data: serverType,
|
||||||
|
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) {
|
||||||
|
server = hetznerServer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (server == null) {
|
||||||
|
const String msg = 'getServerType: no server!';
|
||||||
|
print(msg);
|
||||||
|
return GenericResult(
|
||||||
|
success: false,
|
||||||
|
data: serverType,
|
||||||
|
message: msg,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
double? priceValue;
|
||||||
|
for (final price in server.serverType.prices) {
|
||||||
|
if (price.location == server.location.name) {
|
||||||
|
priceValue = price.monthly;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (priceValue == null) {
|
||||||
|
const String msg = 'getServerType: no price!';
|
||||||
|
print(msg);
|
||||||
|
return GenericResult(
|
||||||
|
success: false,
|
||||||
|
data: serverType,
|
||||||
|
message: msg,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return GenericResult(
|
||||||
|
success: true,
|
||||||
|
data: ServerType(
|
||||||
|
title: server.serverType.description,
|
||||||
|
identifier: server.serverType.name,
|
||||||
|
ram: server.serverType.memory.toDouble(),
|
||||||
|
cores: server.serverType.cores,
|
||||||
|
disk: DiskSize(byte: server.serverType.disk * 1024 * 1024 * 1024),
|
||||||
|
price: Price(
|
||||||
|
value: priceValue,
|
||||||
|
currency: currency,
|
||||||
|
),
|
||||||
|
location: ServerProviderLocation(
|
||||||
|
title: server.location.city,
|
||||||
|
description: server.location.description,
|
||||||
|
flag: server.location.flag,
|
||||||
|
identifier: server.location.name,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
Future<GenericResult<CallbackDialogueBranching?>> launchInstallation(
|
||||||
final LaunchInstallationData installationData,
|
final LaunchInstallationData installationData,
|
||||||
|
|
|
@ -24,6 +24,11 @@ abstract class ServerProvider {
|
||||||
/// Only with public IPv4 addresses.
|
/// Only with public IPv4 addresses.
|
||||||
Future<GenericResult<List<ServerBasicInfo>>> getServers();
|
Future<GenericResult<List<ServerBasicInfo>>> getServers();
|
||||||
|
|
||||||
|
/// Returns actual [ServerType] of the
|
||||||
|
/// requested server entry assigned
|
||||||
|
/// to the authorized user.
|
||||||
|
Future<GenericResult<ServerType?>> getServerType(final int serverId);
|
||||||
|
|
||||||
/// Tries to launch installation of SelfPrivacy on
|
/// Tries to launch installation of SelfPrivacy on
|
||||||
/// the requested server entry for the authorized account.
|
/// the requested server entry for the authorized account.
|
||||||
/// Depending on a server provider, the algorithm
|
/// Depending on a server provider, the algorithm
|
||||||
|
|
Loading…
Reference in a new issue