mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(region): Move region settings for provider api to factory
This commit is contained in:
parent
72760e7980
commit
8a93af2b06
|
@ -87,6 +87,9 @@ class BNames {
|
||||||
/// A String field of [serverInstallationBox] box.
|
/// A String field of [serverInstallationBox] box.
|
||||||
static String hetznerKey = 'hetznerKey';
|
static String hetznerKey = 'hetznerKey';
|
||||||
|
|
||||||
|
/// A String field of [serverLocation] box.
|
||||||
|
static String serverLocation = 'serverLocation';
|
||||||
|
|
||||||
/// A String field of [serverInstallationBox] box.
|
/// A String field of [serverInstallationBox] box.
|
||||||
static String cloudFlareKey = 'cloudFlareKey';
|
static String cloudFlareKey = 'cloudFlareKey';
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/cloudflare/cloudflare_factory.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/digital_ocean/digital_ocean_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/digital_ocean/digital_ocean_factory.dart';
|
||||||
|
@ -13,9 +14,9 @@ class UnknownApiProviderException implements Exception {
|
||||||
|
|
||||||
class ApiFactoryCreator {
|
class ApiFactoryCreator {
|
||||||
static ServerProviderApiFactory createServerProviderApiFactory(
|
static ServerProviderApiFactory createServerProviderApiFactory(
|
||||||
final ServerProvider provider,
|
final ServerProviderApiFactorySettings settings,
|
||||||
) {
|
) {
|
||||||
switch (provider) {
|
switch (settings.provider) {
|
||||||
case ServerProvider.hetzner:
|
case ServerProvider.hetzner:
|
||||||
return HetznerApiFactory();
|
return HetznerApiFactory();
|
||||||
case ServerProvider.digitalOcean:
|
case ServerProvider.digitalOcean:
|
||||||
|
@ -26,9 +27,9 @@ class ApiFactoryCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
static DnsProviderApiFactory createDnsProviderApiFactory(
|
static DnsProviderApiFactory createDnsProviderApiFactory(
|
||||||
final DnsProvider provider,
|
final DnsProviderApiFactorySettings settings,
|
||||||
) {
|
) {
|
||||||
switch (provider) {
|
switch (settings.provider) {
|
||||||
case DnsProvider.cloudflare:
|
case DnsProvider.cloudflare:
|
||||||
return CloudflareApiFactory();
|
return CloudflareApiFactory();
|
||||||
case DnsProvider.unknown:
|
case DnsProvider.unknown:
|
||||||
|
@ -39,9 +40,9 @@ class ApiFactoryCreator {
|
||||||
|
|
||||||
class VolumeApiFactoryCreator {
|
class VolumeApiFactoryCreator {
|
||||||
static VolumeProviderApiFactory createVolumeProviderApiFactory(
|
static VolumeProviderApiFactory createVolumeProviderApiFactory(
|
||||||
final ServerProvider provider,
|
final ServerProviderApiFactorySettings settings,
|
||||||
) {
|
) {
|
||||||
switch (provider) {
|
switch (settings.provider) {
|
||||||
case ServerProvider.hetzner:
|
case ServerProvider.hetzner:
|
||||||
return HetznerApiFactory();
|
return HetznerApiFactory();
|
||||||
case ServerProvider.digitalOcean:
|
case ServerProvider.digitalOcean:
|
||||||
|
|
20
lib/logic/api_maps/rest_maps/api_factory_settings.dart
Normal file
20
lib/logic/api_maps/rest_maps/api_factory_settings.dart
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
|
|
||||||
|
class ServerProviderApiFactorySettings {
|
||||||
|
ServerProviderApiFactorySettings({
|
||||||
|
required this.provider,
|
||||||
|
this.location,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ServerProvider provider;
|
||||||
|
final String? location;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DnsProviderApiFactorySettings {
|
||||||
|
DnsProviderApiFactorySettings({
|
||||||
|
required this.provider,
|
||||||
|
});
|
||||||
|
|
||||||
|
final DnsProvider provider;
|
||||||
|
}
|
|
@ -27,7 +27,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
@override
|
@override
|
||||||
bool isWithToken;
|
bool isWithToken;
|
||||||
|
|
||||||
final String region;
|
final String? region;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
BaseOptions get options {
|
BaseOptions get options {
|
||||||
|
@ -631,6 +631,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
value: rawSize['price_monthly'],
|
value: rawSize['price_monthly'],
|
||||||
currency: 'USD',
|
currency: 'USD',
|
||||||
),
|
),
|
||||||
|
location: location,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,8 @@ class DigitalOceanApiFactory extends ServerProviderApiFactory
|
||||||
with VolumeProviderApiFactory {
|
with VolumeProviderApiFactory {
|
||||||
@override
|
@override
|
||||||
ServerProviderApi getServerProvider({
|
ServerProviderApi getServerProvider({
|
||||||
required final ServerProviderApiSettings settings,
|
final ServerProviderApiSettings settings =
|
||||||
|
const ServerProviderApiSettings(),
|
||||||
}) =>
|
}) =>
|
||||||
DigitalOceanApi(
|
DigitalOceanApi(
|
||||||
region: settings.region,
|
region: settings.region,
|
||||||
|
@ -18,7 +19,8 @@ class DigitalOceanApiFactory extends ServerProviderApiFactory
|
||||||
|
|
||||||
@override
|
@override
|
||||||
VolumeProviderApi getVolumeProvider({
|
VolumeProviderApi getVolumeProvider({
|
||||||
required final ServerProviderApiSettings settings,
|
final ServerProviderApiSettings settings =
|
||||||
|
const ServerProviderApiSettings(),
|
||||||
}) =>
|
}) =>
|
||||||
DigitalOceanApi(
|
DigitalOceanApi(
|
||||||
region: settings.region,
|
region: settings.region,
|
||||||
|
|
|
@ -18,7 +18,7 @@ import 'package:selfprivacy/utils/password_generator.dart';
|
||||||
|
|
||||||
class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
HetznerApi({
|
HetznerApi({
|
||||||
required this.region,
|
this.region,
|
||||||
this.hasLogger = false,
|
this.hasLogger = false,
|
||||||
this.isWithToken = true,
|
this.isWithToken = true,
|
||||||
});
|
});
|
||||||
|
@ -27,7 +27,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
@override
|
@override
|
||||||
bool isWithToken;
|
bool isWithToken;
|
||||||
|
|
||||||
final String region;
|
final String? region;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
BaseOptions get options {
|
BaseOptions get options {
|
||||||
|
@ -336,25 +336,25 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
final String userdataString =
|
final String userdataString =
|
||||||
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$hostname bash 2>&1 | tee /tmp/infect.log";
|
"#cloud-config\nruncmd:\n- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/master/nixos-infect | PROVIDER=hetzner NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$dbPassword API_TOKEN=$apiToken HOSTNAME=$hostname bash 2>&1 | tee /tmp/infect.log";
|
||||||
|
|
||||||
final Map<String, Object> data = {
|
|
||||||
'name': hostname,
|
|
||||||
'server_type': 'cx11',
|
|
||||||
'start_after_create': false,
|
|
||||||
'image': 'ubuntu-20.04',
|
|
||||||
'volumes': [dbId],
|
|
||||||
'networks': [],
|
|
||||||
'user_data': userdataString,
|
|
||||||
'labels': {},
|
|
||||||
'automount': true,
|
|
||||||
'location': region,
|
|
||||||
};
|
|
||||||
print('Decoded data: $data');
|
|
||||||
|
|
||||||
ServerHostingDetails? serverDetails;
|
ServerHostingDetails? serverDetails;
|
||||||
DioError? hetznerError;
|
DioError? hetznerError;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
final Map<String, Object> data = {
|
||||||
|
'name': hostname,
|
||||||
|
'server_type': 'cx11',
|
||||||
|
'start_after_create': false,
|
||||||
|
'image': 'ubuntu-20.04',
|
||||||
|
'volumes': [dbId],
|
||||||
|
'networks': [],
|
||||||
|
'user_data': userdataString,
|
||||||
|
'labels': {},
|
||||||
|
'automount': true,
|
||||||
|
'location': region!,
|
||||||
|
};
|
||||||
|
print('Decoded data: $data');
|
||||||
|
|
||||||
final Response serverCreateResponse = await client.post(
|
final Response serverCreateResponse = await client.post(
|
||||||
'/servers',
|
'/servers',
|
||||||
data: data,
|
data: data,
|
||||||
|
@ -616,6 +616,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
value: rawPrice['price_monthly']['gross'],
|
value: rawPrice['price_monthly']['gross'],
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
),
|
),
|
||||||
|
location: location,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,22 +6,28 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_pro
|
||||||
|
|
||||||
class HetznerApiFactory extends ServerProviderApiFactory
|
class HetznerApiFactory extends ServerProviderApiFactory
|
||||||
with VolumeProviderApiFactory {
|
with VolumeProviderApiFactory {
|
||||||
|
HetznerApiFactory({this.region});
|
||||||
|
|
||||||
|
final String? region;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
ServerProviderApi getServerProvider({
|
ServerProviderApi getServerProvider({
|
||||||
required final ServerProviderApiSettings settings,
|
final ServerProviderApiSettings settings =
|
||||||
|
const ServerProviderApiSettings(),
|
||||||
}) =>
|
}) =>
|
||||||
HetznerApi(
|
HetznerApi(
|
||||||
region: settings.region,
|
region: settings.region ?? region,
|
||||||
hasLogger: settings.hasLogger,
|
hasLogger: settings.hasLogger,
|
||||||
isWithToken: settings.isWithToken,
|
isWithToken: settings.isWithToken,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
VolumeProviderApi getVolumeProvider({
|
VolumeProviderApi getVolumeProvider({
|
||||||
required final ServerProviderApiSettings settings,
|
final ServerProviderApiSettings settings =
|
||||||
|
const ServerProviderApiSettings(),
|
||||||
}) =>
|
}) =>
|
||||||
HetznerApi(
|
HetznerApi(
|
||||||
region: settings.region,
|
region: settings.region ?? region,
|
||||||
hasLogger: settings.hasLogger,
|
hasLogger: settings.hasLogger,
|
||||||
isWithToken: settings.isWithToken,
|
isWithToken: settings.isWithToken,
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,10 +2,10 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/provider_api_settings.dart'
|
||||||
|
|
||||||
class ServerProviderApiSettings extends ProviderApiSettings {
|
class ServerProviderApiSettings extends ProviderApiSettings {
|
||||||
const ServerProviderApiSettings({
|
const ServerProviderApiSettings({
|
||||||
required this.region,
|
this.region,
|
||||||
super.hasLogger = false,
|
super.hasLogger = false,
|
||||||
super.isWithToken = true,
|
super.isWithToken = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String region;
|
final String? region;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_pro
|
||||||
|
|
||||||
abstract class ServerProviderApiFactory {
|
abstract class ServerProviderApiFactory {
|
||||||
ServerProviderApi getServerProvider({
|
ServerProviderApi getServerProvider({
|
||||||
required final ServerProviderApiSettings settings,
|
final ServerProviderApiSettings settings,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin VolumeProviderApiFactory {
|
mixin VolumeProviderApiFactory {
|
||||||
VolumeProviderApi getVolumeProvider({
|
VolumeProviderApi getVolumeProvider({
|
||||||
required final ServerProviderApiSettings settings,
|
final ServerProviderApiSettings settings,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||||
|
@ -20,8 +21,9 @@ class DnsRecordsCubit
|
||||||
|
|
||||||
DnsProviderApiFactory? dnsProviderApiFactory =
|
DnsProviderApiFactory? dnsProviderApiFactory =
|
||||||
ApiFactoryCreator.createDnsProviderApiFactory(
|
ApiFactoryCreator.createDnsProviderApiFactory(
|
||||||
DnsProvider.cloudflare, // TODO: HARDCODE FOR NOW!!!
|
DnsProviderApiFactorySettings(provider: DnsProvider.cloudflare),
|
||||||
); // TODO: Remove when provider selection is implemented.
|
); // TODO: HARDCODE FOR NOW!!!
|
||||||
|
// TODO: Remove when provider selection is implemented.
|
||||||
|
|
||||||
final ServerApi api = ServerApi();
|
final ServerApi api = ServerApi();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
||||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
import 'package:selfprivacy/logic/models/hetzner_metrics.dart';
|
import 'package:selfprivacy/logic/models/hetzner_metrics.dart';
|
||||||
|
@ -27,8 +28,9 @@ class HetznerMetricsRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
final HetznerApi api = HetznerApi(
|
final HetznerApi api = HetznerApi(
|
||||||
|
/// TODO: Hetzner hardcode (???)
|
||||||
hasLogger: false,
|
hasLogger: false,
|
||||||
region: 'fra1',
|
region: getIt<ApiConfigModel>().serverLocation,
|
||||||
);
|
);
|
||||||
|
|
||||||
final List<Map<String, dynamic>> results = await Future.wait([
|
final List<Map<String, dynamic>> results = await Future.wait([
|
||||||
|
|
|
@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_factory.dart';
|
||||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
|
@ -25,22 +26,21 @@ class ApiProviderVolumeCubit
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
if (serverInstallationCubit.state is ServerInstallationFinished) {
|
if (serverInstallationCubit.state is ServerInstallationFinished) {
|
||||||
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
final serverDetails = getIt<ApiConfigModel>().serverDetails;
|
||||||
|
final serverLocation = getIt<ApiConfigModel>().serverLocation;
|
||||||
providerApi = serverDetails == null
|
providerApi = serverDetails == null
|
||||||
? null
|
? null
|
||||||
: VolumeApiFactoryCreator.createVolumeProviderApiFactory(
|
: VolumeApiFactoryCreator.createVolumeProviderApiFactory(
|
||||||
getIt<ApiConfigModel>().serverDetails!.provider,
|
ServerProviderApiFactorySettings(
|
||||||
|
location: serverLocation,
|
||||||
|
provider: getIt<ApiConfigModel>().serverDetails!.provider,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
_refetch();
|
_refetch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Price?> getPricePerGb() async => providerApi!
|
Future<Price?> getPricePerGb() async =>
|
||||||
.getVolumeProvider(
|
providerApi!.getVolumeProvider().getPricePerGb();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.getPricePerGb();
|
|
||||||
|
|
||||||
Future<void> refresh() async {
|
Future<void> refresh() async {
|
||||||
emit(const ApiProviderVolumeState([], LoadingStatus.refreshing, false));
|
emit(const ApiProviderVolumeState([], LoadingStatus.refreshing, false));
|
||||||
|
@ -52,13 +52,8 @@ class ApiProviderVolumeCubit
|
||||||
return emit(const ApiProviderVolumeState([], LoadingStatus.error, false));
|
return emit(const ApiProviderVolumeState([], LoadingStatus.error, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<ServerVolume> volumes = await providerApi!
|
final List<ServerVolume> volumes =
|
||||||
.getVolumeProvider(
|
await providerApi!.getVolumeProvider().getVolumes();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.getVolumes();
|
|
||||||
|
|
||||||
if (volumes.isEmpty) {
|
if (volumes.isEmpty) {
|
||||||
return emit(const ApiProviderVolumeState([], LoadingStatus.error, false));
|
return emit(const ApiProviderVolumeState([], LoadingStatus.error, false));
|
||||||
|
@ -70,22 +65,14 @@ class ApiProviderVolumeCubit
|
||||||
Future<void> attachVolume(final DiskVolume volume) async {
|
Future<void> attachVolume(final DiskVolume volume) async {
|
||||||
final ServerHostingDetails server = getIt<ApiConfigModel>().serverDetails!;
|
final ServerHostingDetails server = getIt<ApiConfigModel>().serverDetails!;
|
||||||
await providerApi!
|
await providerApi!
|
||||||
.getVolumeProvider(
|
.getVolumeProvider()
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.attachVolume(volume.providerVolume!.id.toString(), server.id);
|
.attachVolume(volume.providerVolume!.id.toString(), server.id);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> detachVolume(final DiskVolume volume) async {
|
Future<void> detachVolume(final DiskVolume volume) async {
|
||||||
await providerApi!
|
await providerApi!
|
||||||
.getVolumeProvider(
|
.getVolumeProvider()
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.detachVolume(volume.providerVolume!.id.toString());
|
.detachVolume(volume.providerVolume!.id.toString());
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
@ -99,13 +86,7 @@ class ApiProviderVolumeCubit
|
||||||
'Starting resize',
|
'Starting resize',
|
||||||
);
|
);
|
||||||
emit(state.copyWith(isResizing: true));
|
emit(state.copyWith(isResizing: true));
|
||||||
final bool resized = await providerApi!
|
final bool resized = await providerApi!.getVolumeProvider().resizeVolume(
|
||||||
.getVolumeProvider(
|
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.resizeVolume(
|
|
||||||
volume.providerVolume!.id.toString(),
|
volume.providerVolume!.id.toString(),
|
||||||
newSizeGb,
|
newSizeGb,
|
||||||
);
|
);
|
||||||
|
@ -141,13 +122,8 @@ class ApiProviderVolumeCubit
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> createVolume() async {
|
Future<void> createVolume() async {
|
||||||
final ServerVolume? volume = await providerApi!
|
final ServerVolume? volume =
|
||||||
.getVolumeProvider(
|
await providerApi!.getVolumeProvider().createVolume();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.createVolume();
|
|
||||||
|
|
||||||
final diskVolume = DiskVolume(providerVolume: volume);
|
final diskVolume = DiskVolume(providerVolume: volume);
|
||||||
await attachVolume(diskVolume);
|
await attachVolume(diskVolume);
|
||||||
|
@ -160,11 +136,7 @@ class ApiProviderVolumeCubit
|
||||||
|
|
||||||
Future<void> deleteVolume(final DiskVolume volume) async {
|
Future<void> deleteVolume(final DiskVolume volume) async {
|
||||||
await providerApi!
|
await providerApi!
|
||||||
.getVolumeProvider(
|
.getVolumeProvider()
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.deleteVolume(volume.providerVolume!.id.toString());
|
.deleteVolume(volume.providerVolume!.id.toString());
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/hetzner/hetzner.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server.dart';
|
||||||
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
||||||
|
@ -5,7 +6,10 @@ import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
|
|
||||||
class ServerDetailsRepository {
|
class ServerDetailsRepository {
|
||||||
HetznerApi hetzner = HetznerApi(region: 'fra1');
|
HetznerApi hetzner = HetznerApi(
|
||||||
|
/// TODO: Hetzner hardcode (???)
|
||||||
|
region: getIt<ApiConfigModel>().serverLocation,
|
||||||
|
);
|
||||||
ServerApi server = ServerApi();
|
ServerApi server = ServerApi();
|
||||||
|
|
||||||
Future<ServerDetailsRepositoryDto> load() async {
|
Future<ServerDetailsRepositoryDto> load() async {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider_api_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
|
@ -57,17 +58,15 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
void setServerProviderType(final ServerProvider providerType) {
|
void setServerProviderType(final ServerProvider providerType) {
|
||||||
repository.serverProviderApiFactory =
|
repository.serverProviderApiFactory =
|
||||||
ApiFactoryCreator.createServerProviderApiFactory(
|
ApiFactoryCreator.createServerProviderApiFactory(
|
||||||
providerType,
|
ServerProviderApiFactorySettings(
|
||||||
|
provider: providerType,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
RegExp getServerProviderApiTokenValidation() =>
|
RegExp getServerProviderApiTokenValidation() =>
|
||||||
repository.serverProviderApiFactory!
|
repository.serverProviderApiFactory!
|
||||||
.getServerProvider(
|
.getServerProvider()
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.getApiTokenValidation();
|
.getApiTokenValidation();
|
||||||
|
|
||||||
RegExp getDnsProviderApiTokenValidation() => repository.dnsProviderApiFactory!
|
RegExp getDnsProviderApiTokenValidation() => repository.dnsProviderApiFactory!
|
||||||
|
@ -80,7 +79,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
repository.serverProviderApiFactory!
|
repository.serverProviderApiFactory!
|
||||||
.getServerProvider(
|
.getServerProvider(
|
||||||
settings: const ServerProviderApiSettings(
|
settings: const ServerProviderApiSettings(
|
||||||
region: 'fra1',
|
|
||||||
isWithToken: false,
|
isWithToken: false,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -101,9 +99,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository.serverProviderApiFactory!
|
return repository.serverProviderApiFactory!
|
||||||
.getServerProvider(
|
.getServerProvider()
|
||||||
settings: const ServerProviderApiSettings(region: 'fra1'),
|
|
||||||
)
|
|
||||||
.getAvailableLocations();
|
.getAvailableLocations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +111,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
}
|
}
|
||||||
|
|
||||||
return repository.serverProviderApiFactory!
|
return repository.serverProviderApiFactory!
|
||||||
.getServerProvider(
|
.getServerProvider()
|
||||||
settings: const ServerProviderApiSettings(region: 'fra1'),
|
|
||||||
)
|
|
||||||
.getServerTypesByLocation(location: location);
|
.getServerTypesByLocation(location: location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,12 +135,20 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setServerType(final String serverTypeId) async {
|
void setServerType(final ServerType serverType) async {
|
||||||
await repository.saveServerType(serverTypeId);
|
await repository.saveServerType(serverType);
|
||||||
|
|
||||||
|
repository.serverProviderApiFactory =
|
||||||
|
ApiFactoryCreator.createServerProviderApiFactory(
|
||||||
|
ServerProviderApiFactorySettings(
|
||||||
|
provider: getIt<ApiConfigModel>().serverDetails!.provider,
|
||||||
|
location: serverType.location.identifier,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
(state as ServerInstallationNotFinished).copyWith(
|
(state as ServerInstallationNotFinished).copyWith(
|
||||||
serverTypeIdentificator: serverTypeId,
|
serverTypeIdentificator: serverType.identifier,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import 'package:pub_semver/pub_semver.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/config/hive_config.dart';
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_creator.dart';
|
||||||
|
import 'package:selfprivacy/logic/api_maps/rest_maps/api_factory_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_factory.dart';
|
||||||
|
@ -25,6 +26,7 @@ import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:selfprivacy/logic/models/json/device_token.dart';
|
import 'package:selfprivacy/logic/models/json/device_token.dart';
|
||||||
import 'package:selfprivacy/logic/models/message.dart';
|
import 'package:selfprivacy/logic/models/message.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
import 'package:selfprivacy/logic/models/server_basic_info.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/server_type.dart';
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
||||||
|
|
||||||
|
@ -44,11 +46,14 @@ class ServerInstallationRepository {
|
||||||
ServerProviderApiFactory? serverProviderApiFactory;
|
ServerProviderApiFactory? serverProviderApiFactory;
|
||||||
DnsProviderApiFactory? dnsProviderApiFactory =
|
DnsProviderApiFactory? dnsProviderApiFactory =
|
||||||
ApiFactoryCreator.createDnsProviderApiFactory(
|
ApiFactoryCreator.createDnsProviderApiFactory(
|
||||||
DnsProvider.cloudflare, // TODO: HARDCODE FOR NOW!!!
|
DnsProviderApiFactorySettings(
|
||||||
|
provider: DnsProvider.cloudflare,
|
||||||
|
), // TODO: HARDCODE FOR NOW!!!
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<ServerInstallationState> load() async {
|
Future<ServerInstallationState> load() async {
|
||||||
final String? providerApiToken = getIt<ApiConfigModel>().serverProviderKey;
|
final String? providerApiToken = getIt<ApiConfigModel>().serverProviderKey;
|
||||||
|
final String? location = getIt<ApiConfigModel>().serverLocation;
|
||||||
final String? cloudflareToken = getIt<ApiConfigModel>().cloudFlareKey;
|
final String? cloudflareToken = getIt<ApiConfigModel>().cloudFlareKey;
|
||||||
final String? serverTypeIdentificator = getIt<ApiConfigModel>().serverType;
|
final String? serverTypeIdentificator = getIt<ApiConfigModel>().serverType;
|
||||||
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
final ServerDomain? serverDomain = getIt<ApiConfigModel>().serverDomain;
|
||||||
|
@ -61,13 +66,18 @@ class ServerInstallationRepository {
|
||||||
serverDetails.provider != ServerProvider.unknown) {
|
serverDetails.provider != ServerProvider.unknown) {
|
||||||
serverProviderApiFactory =
|
serverProviderApiFactory =
|
||||||
ApiFactoryCreator.createServerProviderApiFactory(
|
ApiFactoryCreator.createServerProviderApiFactory(
|
||||||
serverDetails.provider,
|
ServerProviderApiFactorySettings(
|
||||||
|
provider: serverDetails.provider,
|
||||||
|
location: location,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverDomain != null && serverDomain.provider != DnsProvider.unknown) {
|
if (serverDomain != null && serverDomain.provider != DnsProvider.unknown) {
|
||||||
dnsProviderApiFactory = ApiFactoryCreator.createDnsProviderApiFactory(
|
dnsProviderApiFactory = ApiFactoryCreator.createDnsProviderApiFactory(
|
||||||
serverDomain.provider,
|
DnsProviderApiFactorySettings(
|
||||||
|
provider: serverDomain.provider,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,11 +165,7 @@ class ServerInstallationRepository {
|
||||||
) async {
|
) async {
|
||||||
ServerHostingDetails serverDetails;
|
ServerHostingDetails serverDetails;
|
||||||
|
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
serverDetails = await api.powerOn();
|
serverDetails = await api.powerOn();
|
||||||
|
|
||||||
return serverDetails;
|
return serverDetails;
|
||||||
|
@ -235,11 +241,7 @@ class ServerInstallationRepository {
|
||||||
required final Future<void> Function(ServerHostingDetails serverDetails)
|
required final Future<void> Function(ServerHostingDetails serverDetails)
|
||||||
onSuccess,
|
onSuccess,
|
||||||
}) async {
|
}) async {
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
final ServerHostingDetails? serverDetails = await api.createServer(
|
final ServerHostingDetails? serverDetails = await api.createServer(
|
||||||
dnsApiToken: cloudFlareKey,
|
dnsApiToken: cloudFlareKey,
|
||||||
|
@ -344,11 +346,7 @@ class ServerInstallationRepository {
|
||||||
final DnsProviderApi dnsProviderApi =
|
final DnsProviderApi dnsProviderApi =
|
||||||
dnsProviderApiFactory!.getDnsProvider();
|
dnsProviderApiFactory!.getDnsProvider();
|
||||||
final ServerProviderApi serverApi =
|
final ServerProviderApi serverApi =
|
||||||
serverProviderApiFactory!.getServerProvider(
|
serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
await dnsProviderApi.removeSimilarRecords(
|
await dnsProviderApi.removeSimilarRecords(
|
||||||
ip4: serverDetails.ip4,
|
ip4: serverDetails.ip4,
|
||||||
|
@ -420,20 +418,12 @@ class ServerInstallationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerHostingDetails> restart() async {
|
Future<ServerHostingDetails> restart() async {
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return api.restart();
|
return api.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerHostingDetails> powerOn() async {
|
Future<ServerHostingDetails> powerOn() async {
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return api.powerOn();
|
return api.powerOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,11 +666,7 @@ class ServerInstallationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ServerBasicInfo>> getServersOnProviderAccount() async {
|
Future<List<ServerBasicInfo>> getServersOnProviderAccount() async {
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
return api.getServers();
|
return api.getServers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -699,8 +685,13 @@ class ServerInstallationRepository {
|
||||||
await getIt<ApiConfigModel>().storeServerProviderKey(key);
|
await getIt<ApiConfigModel>().storeServerProviderKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> saveServerType(final String serverType) async {
|
Future<void> saveServerType(final ServerType serverType) async {
|
||||||
await getIt<ApiConfigModel>().storeServerTypeIdentifier(serverType);
|
await getIt<ApiConfigModel>().storeServerTypeIdentifier(
|
||||||
|
serverType.identifier,
|
||||||
|
);
|
||||||
|
await getIt<ApiConfigModel>().storeServerLocation(
|
||||||
|
serverType.location.identifier,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteServerProviderKey() async {
|
Future<void> deleteServerProviderKey() async {
|
||||||
|
@ -762,11 +753,7 @@ class ServerInstallationRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> deleteServer(final ServerDomain serverDomain) async {
|
Future<void> deleteServer(final ServerDomain serverDomain) async {
|
||||||
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider(
|
final ServerProviderApi api = serverProviderApiFactory!.getServerProvider();
|
||||||
settings: const ServerProviderApiSettings(
|
|
||||||
region: 'fra1',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final DnsProviderApi dnsProviderApi =
|
final DnsProviderApi dnsProviderApi =
|
||||||
dnsProviderApiFactory!.getDnsProvider();
|
dnsProviderApiFactory!.getDnsProvider();
|
||||||
|
|
||||||
|
|
|
@ -172,7 +172,8 @@ class ServerInstallationNotFinished extends ServerInstallationState {
|
||||||
}) =>
|
}) =>
|
||||||
ServerInstallationNotFinished(
|
ServerInstallationNotFinished(
|
||||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||||
serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator,
|
serverTypeIdentificator:
|
||||||
|
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
||||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||||
serverDomain: serverDomain ?? this.serverDomain,
|
serverDomain: serverDomain ?? this.serverDomain,
|
||||||
|
@ -316,7 +317,8 @@ class ServerInstallationRecovery extends ServerInstallationState {
|
||||||
}) =>
|
}) =>
|
||||||
ServerInstallationRecovery(
|
ServerInstallationRecovery(
|
||||||
providerApiToken: providerApiToken ?? this.providerApiToken,
|
providerApiToken: providerApiToken ?? this.providerApiToken,
|
||||||
serverTypeIdentificator: serverTypeIdentificator ?? this.serverTypeIdentificator,
|
serverTypeIdentificator:
|
||||||
|
serverTypeIdentificator ?? this.serverTypeIdentificator,
|
||||||
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
|
||||||
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
|
||||||
serverDomain: serverDomain ?? this.serverDomain,
|
serverDomain: serverDomain ?? this.serverDomain,
|
||||||
|
|
|
@ -10,6 +10,7 @@ class ApiConfigModel {
|
||||||
|
|
||||||
ServerHostingDetails? get serverDetails => _serverDetails;
|
ServerHostingDetails? get serverDetails => _serverDetails;
|
||||||
String? get serverProviderKey => _serverProviderKey;
|
String? get serverProviderKey => _serverProviderKey;
|
||||||
|
String? get serverLocation => _serverLocation;
|
||||||
String? get serverType => _serverType;
|
String? get serverType => _serverType;
|
||||||
String? get cloudFlareKey => _cloudFlareKey;
|
String? get cloudFlareKey => _cloudFlareKey;
|
||||||
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
||||||
|
@ -17,6 +18,7 @@ class ApiConfigModel {
|
||||||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||||
|
|
||||||
String? _serverProviderKey;
|
String? _serverProviderKey;
|
||||||
|
String? _serverLocation;
|
||||||
String? _cloudFlareKey;
|
String? _cloudFlareKey;
|
||||||
String? _serverType;
|
String? _serverType;
|
||||||
ServerHostingDetails? _serverDetails;
|
ServerHostingDetails? _serverDetails;
|
||||||
|
@ -39,6 +41,11 @@ class ApiConfigModel {
|
||||||
_serverType = typeIdentifier;
|
_serverType = typeIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> storeServerLocation(final String serverLocation) async {
|
||||||
|
await _box.put(BNames.serverLocation, serverLocation);
|
||||||
|
_serverLocation = serverLocation;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> storeBackblazeCredential(final BackblazeCredential value) async {
|
Future<void> storeBackblazeCredential(final BackblazeCredential value) async {
|
||||||
await _box.put(BNames.backblazeCredential, value);
|
await _box.put(BNames.backblazeCredential, value);
|
||||||
_backblazeCredential = value;
|
_backblazeCredential = value;
|
||||||
|
@ -61,19 +68,23 @@ class ApiConfigModel {
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
_serverProviderKey = null;
|
_serverProviderKey = null;
|
||||||
|
_serverLocation = null;
|
||||||
_cloudFlareKey = null;
|
_cloudFlareKey = null;
|
||||||
_backblazeCredential = null;
|
_backblazeCredential = null;
|
||||||
_serverDomain = null;
|
_serverDomain = null;
|
||||||
_serverDetails = null;
|
_serverDetails = null;
|
||||||
_backblazeBucket = null;
|
_backblazeBucket = null;
|
||||||
|
_serverType = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
_serverProviderKey = _box.get(BNames.hetznerKey);
|
_serverProviderKey = _box.get(BNames.hetznerKey);
|
||||||
|
_serverLocation = _box.get(BNames.serverLocation);
|
||||||
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
|
_cloudFlareKey = _box.get(BNames.cloudFlareKey);
|
||||||
_backblazeCredential = _box.get(BNames.backblazeCredential);
|
_backblazeCredential = _box.get(BNames.backblazeCredential);
|
||||||
_serverDomain = _box.get(BNames.serverDomain);
|
_serverDomain = _box.get(BNames.serverDomain);
|
||||||
_serverDetails = _box.get(BNames.serverDetails);
|
_serverDetails = _box.get(BNames.serverDetails);
|
||||||
_backblazeBucket = _box.get(BNames.backblazeBucket);
|
_backblazeBucket = _box.get(BNames.backblazeBucket);
|
||||||
|
_serverType = _box.get(BNames.serverTypeIdentifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:selfprivacy/logic/models/disk_size.dart';
|
import 'package:selfprivacy/logic/models/disk_size.dart';
|
||||||
import 'package:selfprivacy/logic/models/price.dart';
|
import 'package:selfprivacy/logic/models/price.dart';
|
||||||
|
import 'package:selfprivacy/logic/models/server_provider_location.dart';
|
||||||
|
|
||||||
class ServerType {
|
class ServerType {
|
||||||
ServerType({
|
ServerType({
|
||||||
|
@ -9,6 +10,7 @@ class ServerType {
|
||||||
required this.cores,
|
required this.cores,
|
||||||
required this.disk,
|
required this.disk,
|
||||||
required this.price,
|
required this.price,
|
||||||
|
required this.location,
|
||||||
});
|
});
|
||||||
final String title;
|
final String title;
|
||||||
final String identifier;
|
final String identifier;
|
||||||
|
@ -16,4 +18,5 @@ class ServerType {
|
||||||
final DiskSize disk;
|
final DiskSize disk;
|
||||||
final int cores;
|
final int cores;
|
||||||
final Price price;
|
final Price price;
|
||||||
|
final ServerProviderLocation location;
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ class SelectTypePage extends StatelessWidget {
|
||||||
...(snapshot.data! as List<ServerType>).map(
|
...(snapshot.data! as List<ServerType>).map(
|
||||||
(final type) => InkWell(
|
(final type) => InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
serverInstallationCubit.setServerType(type.identifier);
|
serverInstallationCubit.setServerType(type);
|
||||||
},
|
},
|
||||||
child: Card(
|
child: Card(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
@ -153,7 +153,8 @@ class SelectTypePage extends StatelessWidget {
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text('disk: $type.disk.gibibyte'),
|
Text('disk: $type.disk.gibibyte'),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text('price: $type.price.value $type.price.currency'),
|
Text(
|
||||||
|
'price: $type.price.value $type.price.currency'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue