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.saveIsServerResetedSecondTime(true);
|
||||||
await repository.saveHasFinalChecked(true);
|
await repository.saveHasFinalChecked(true);
|
||||||
await repository.saveIsRecoveringServer(false);
|
await repository.saveIsRecoveringServer(false);
|
||||||
final serverInfo = await ProvidersController.currentServerProvider!
|
final serverType = await ProvidersController.currentServerProvider!
|
||||||
.getServerInfo(state.serverDetails!.id);
|
.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: serverInfo.data?.serverTypeId ?? '',
|
serverTypeIdentificator: serverType.data!.identifier,
|
||||||
);
|
);
|
||||||
emit(updatedState.finish());
|
emit(updatedState.finish());
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,54 +90,90 @@ class DigitalOceanServerProvider extends ServerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
Future<GenericResult<ServerType?>> getServerType(final int serverId) async {
|
||||||
final int serverId,
|
ServerType? serverType;
|
||||||
) async {
|
dynamic server;
|
||||||
ServerBasicInfo? server;
|
|
||||||
final result = await _adapter.api().getServers();
|
final result = await _adapter.api().getServers();
|
||||||
if (result.data.isEmpty || !result.success) {
|
if (result.data.isEmpty || !result.success) {
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
success: result.success,
|
success: result.success,
|
||||||
data: server,
|
data: serverType,
|
||||||
code: result.code,
|
code: result.code,
|
||||||
message: result.message,
|
message: result.message,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final rawServers = result.data;
|
final List rawServers = result.data;
|
||||||
for (final rawServer in rawServers) {
|
for (final rawServer in rawServers) {
|
||||||
String? ipv4;
|
|
||||||
if (rawServer['networks']['v4'].isNotEmpty) {
|
if (rawServer['networks']['v4'].isNotEmpty) {
|
||||||
for (final v4 in rawServer['networks']['v4']) {
|
for (final v4 in rawServer['networks']['v4']) {
|
||||||
if (v4['type'].toString() == 'public') {
|
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) {
|
if (server == null) {
|
||||||
|
const String msg = 'getServerType: no server!';
|
||||||
|
print(msg);
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
success: false,
|
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
|
@override
|
||||||
|
|
|
@ -90,15 +90,14 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(
|
Future<GenericResult<ServerType?>> getServerType(final int serverId) async {
|
||||||
final int serverId,
|
ServerType? serverType;
|
||||||
) async {
|
HetznerServerInfo? server;
|
||||||
ServerBasicInfo? server;
|
|
||||||
final result = await _adapter.api().getServers();
|
final result = await _adapter.api().getServers();
|
||||||
if (result.data.isEmpty || !result.success) {
|
if (result.data.isEmpty || !result.success) {
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
success: result.success,
|
success: result.success,
|
||||||
data: server,
|
data: serverType,
|
||||||
code: result.code,
|
code: result.code,
|
||||||
message: result.message,
|
message: result.message,
|
||||||
);
|
);
|
||||||
|
@ -106,34 +105,60 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
|
|
||||||
final List<HetznerServerInfo> hetznerServers = result.data;
|
final List<HetznerServerInfo> hetznerServers = result.data;
|
||||||
for (final hetznerServer in hetznerServers) {
|
for (final hetznerServer in hetznerServers) {
|
||||||
if (hetznerServer.publicNet.ipv4 == null ||
|
if (hetznerServer.publicNet.ipv4 != null ||
|
||||||
hetznerServer.id != serverId) {
|
hetznerServer.id == serverId) {
|
||||||
continue;
|
server = hetznerServer;
|
||||||
}
|
break;
|
||||||
|
|
||||||
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) {
|
if (server == null) {
|
||||||
|
const String msg = 'getServerType: no server!';
|
||||||
|
print(msg);
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
success: false,
|
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
|
@override
|
||||||
|
|
|
@ -24,12 +24,10 @@ 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 [ServerBasicInfo] of the
|
/// Returns actual [ServerType] of the
|
||||||
/// requested server entry assigned
|
/// requested server entry assigned
|
||||||
/// to the authorized user.
|
/// to the authorized user.
|
||||||
///
|
Future<GenericResult<ServerType?>> getServerType(final int serverId);
|
||||||
/// Only with public IPv4 address.
|
|
||||||
Future<GenericResult<ServerBasicInfo?>> getServerInfo(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.
|
||||||
|
|
Loading…
Reference in a new issue