mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(recovery): Replace server basic info request method with server type info request method
This commit is contained in:
parent
80f28463ec
commit
7b02074345
|
@ -721,15 +721,18 @@ 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 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();
|
||||
await repository.saveRootUser(mainUser);
|
||||
final ServerInstallationRecovery updatedState =
|
||||
(state as ServerInstallationRecovery).copyWith(
|
||||
backblazeCredential: backblazeCredential,
|
||||
rootUser: mainUser,
|
||||
serverTypeIdentificator: serverInfo.data?.serverTypeId ?? '',
|
||||
serverTypeIdentificator: serverType.data!.identifier,
|
||||
);
|
||||
emit(updatedState.finish());
|
||||
}
|
||||
|
|
|
@ -90,54 +90,90 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
||||
final int serverId,
|
||||
) async {
|
||||
ServerBasicInfo? server;
|
||||
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: server,
|
||||
data: serverType,
|
||||
code: result.code,
|
||||
message: result.message,
|
||||
);
|
||||
}
|
||||
|
||||
final rawServers = result.data;
|
||||
final List 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();
|
||||
server = rawServer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
const String msg = 'getServerType: no server!';
|
||||
print(msg);
|
||||
return GenericResult(
|
||||
success: false,
|
||||
data: server,
|
||||
data: serverType,
|
||||
message: msg,
|
||||
);
|
||||
}
|
||||
|
||||
return GenericResult(success: true, data: server);
|
||||
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
|
||||
|
|
|
@ -90,15 +90,14 @@ class HetznerServerProvider extends ServerProvider {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
||||
final int serverId,
|
||||
) async {
|
||||
ServerBasicInfo? server;
|
||||
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: server,
|
||||
data: serverType,
|
||||
code: result.code,
|
||||
message: result.message,
|
||||
);
|
||||
|
@ -106,34 +105,60 @@ class HetznerServerProvider extends ServerProvider {
|
|||
|
||||
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 (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: server,
|
||||
data: serverType,
|
||||
message: msg,
|
||||
);
|
||||
}
|
||||
|
||||
return GenericResult(success: true, data: server);
|
||||
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
|
||||
|
|
|
@ -24,12 +24,10 @@ abstract class ServerProvider {
|
|||
/// Only with public IPv4 addresses.
|
||||
Future<GenericResult<List<ServerBasicInfo>>> getServers();
|
||||
|
||||
/// Returns actual [ServerBasicInfo] of the
|
||||
/// Returns actual [ServerType] of the
|
||||
/// requested server entry assigned
|
||||
/// to the authorized user.
|
||||
///
|
||||
/// Only with public IPv4 address.
|
||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(final int serverId);
|
||||
Future<GenericResult<ServerType?>> getServerType(final int serverId);
|
||||
|
||||
/// Tries to launch installation of SelfPrivacy on
|
||||
/// the requested server entry for the authorized account.
|
||||
|
|
Loading…
Reference in a new issue