mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
fix(initializing): Make provider and server type picking work
This commit is contained in:
parent
eebff47d0c
commit
cb1fe6eafd
|
@ -87,6 +87,9 @@ class BNames {
|
|||
/// A String field of [serverInstallationBox] box.
|
||||
static String hetznerKey = 'hetznerKey';
|
||||
|
||||
/// A String field of [serverInstallationBox] box.
|
||||
static String serverProvider = 'serverProvider';
|
||||
|
||||
/// A String field of [serverLocation] box.
|
||||
static String serverLocation = 'serverLocation';
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ class ApiFactoryCreator {
|
|||
) {
|
||||
switch (settings.provider) {
|
||||
case ServerProvider.hetzner:
|
||||
return HetznerApiFactory();
|
||||
return HetznerApiFactory(region: settings.location);
|
||||
case ServerProvider.digitalOcean:
|
||||
return DigitalOceanApiFactory();
|
||||
return DigitalOceanApiFactory(region: settings.location);
|
||||
case ServerProvider.unknown:
|
||||
throw UnknownApiProviderException('Unknown server provider');
|
||||
}
|
||||
|
|
|
@ -6,13 +6,17 @@ import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/volume_pro
|
|||
|
||||
class DigitalOceanApiFactory extends ServerProviderApiFactory
|
||||
with VolumeProviderApiFactory {
|
||||
DigitalOceanApiFactory({this.region});
|
||||
|
||||
final String? region;
|
||||
|
||||
@override
|
||||
ServerProviderApi getServerProvider({
|
||||
final ServerProviderApiSettings settings =
|
||||
const ServerProviderApiSettings(),
|
||||
}) =>
|
||||
DigitalOceanApi(
|
||||
region: settings.region,
|
||||
region: settings.region ?? region,
|
||||
hasLogger: settings.hasLogger,
|
||||
isWithToken: settings.isWithToken,
|
||||
);
|
||||
|
@ -23,7 +27,7 @@ class DigitalOceanApiFactory extends ServerProviderApiFactory
|
|||
const ServerProviderApiSettings(),
|
||||
}) =>
|
||||
DigitalOceanApi(
|
||||
region: settings.region,
|
||||
region: settings.region ?? region,
|
||||
hasLogger: settings.hasLogger,
|
||||
isWithToken: settings.isWithToken,
|
||||
);
|
||||
|
|
|
@ -187,8 +187,9 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
return volumes;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ServerVolume?> getVolume(final String volumeId) async {
|
||||
Future<ServerVolume?> getVolume(
|
||||
final String volumeId,
|
||||
) async {
|
||||
ServerVolume? volume;
|
||||
|
||||
final Response dbGetResponse;
|
||||
|
@ -230,7 +231,9 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
|
||||
@override
|
||||
Future<bool> attachVolume(
|
||||
final ServerVolume volume, final int serverId) async {
|
||||
final ServerVolume volume,
|
||||
final int serverId,
|
||||
) async {
|
||||
bool success = false;
|
||||
|
||||
final Response dbPostResponse;
|
||||
|
@ -576,14 +579,16 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
'/locations',
|
||||
);
|
||||
|
||||
locations = response.data!['locations'].map<ServerProviderLocation>(
|
||||
(final location) => ServerProviderLocation(
|
||||
title: location['city'],
|
||||
description: location['description'],
|
||||
flag: getEmojiFlag(location['country']),
|
||||
identifier: location['name'],
|
||||
),
|
||||
);
|
||||
locations = response.data!['locations']
|
||||
.map<ServerProviderLocation>(
|
||||
(final location) => ServerProviderLocation(
|
||||
title: location['city'],
|
||||
description: location['description'],
|
||||
flag: getEmojiFlag(location['country']),
|
||||
identifier: location['name'],
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
|
@ -600,36 +605,36 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
final List<ServerType> types = [];
|
||||
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
final Response response = await client.get(
|
||||
'/server_types',
|
||||
);
|
||||
final rawTypes = response.data!['server_types'];
|
||||
for (final rawType in rawTypes) {
|
||||
for (final rawPrice in rawType['prices']) {
|
||||
if (rawPrice['location'].toString() == location.identifier) {
|
||||
types.add(
|
||||
ServerType(
|
||||
title: rawType['description'],
|
||||
identifier: rawType['name'],
|
||||
ram: rawType['memory'],
|
||||
cores: rawType['cores'],
|
||||
disk: DiskSize(byte: rawType['disk'] * 1024 * 1024 * 1024),
|
||||
price: Price(
|
||||
value: rawPrice['price_monthly']['gross'],
|
||||
currency: 'EUR',
|
||||
),
|
||||
location: location,
|
||||
//try {
|
||||
final Response response = await client.get(
|
||||
'/server_types',
|
||||
);
|
||||
final rawTypes = response.data!['server_types'];
|
||||
for (final rawType in rawTypes) {
|
||||
for (final rawPrice in rawType['prices']) {
|
||||
if (rawPrice['location'].toString() == location.identifier) {
|
||||
types.add(
|
||||
ServerType(
|
||||
title: rawType['description'],
|
||||
identifier: rawType['name'],
|
||||
ram: rawType['memory'],
|
||||
cores: rawType['cores'],
|
||||
disk: DiskSize(byte: rawType['disk'] * 1024 * 1024 * 1024),
|
||||
price: Price(
|
||||
value: double.parse(rawPrice['price_monthly']['gross']),
|
||||
currency: 'EUR',
|
||||
),
|
||||
);
|
||||
}
|
||||
location: location,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
//} catch (e) {
|
||||
//print(e);
|
||||
//} finally {
|
||||
close(client);
|
||||
//}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
}
|
||||
}
|
||||
|
||||
void setServerProviderType(final ServerProvider providerType) {
|
||||
void setServerProviderType(final ServerProvider providerType) async {
|
||||
await repository.saveServerProviderType(providerType);
|
||||
repository.serverProviderApiFactory =
|
||||
ApiFactoryCreator.createServerProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
|
@ -117,7 +118,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
|
||||
void setServerProviderKey(final String serverProviderKey) async {
|
||||
await repository.saveServerProviderKey(serverProviderKey);
|
||||
|
||||
if (state is ServerInstallationRecovery) {
|
||||
emit(
|
||||
(state as ServerInstallationRecovery).copyWith(
|
||||
|
@ -141,7 +141,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
repository.serverProviderApiFactory =
|
||||
ApiFactoryCreator.createServerProviderApiFactory(
|
||||
ServerProviderApiFactorySettings(
|
||||
provider: getIt<ApiConfigModel>().serverDetails!.provider,
|
||||
provider: getIt<ApiConfigModel>().serverProvider!,
|
||||
location: serverType.location.identifier,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -683,6 +683,10 @@ class ServerInstallationRepository {
|
|||
getIt<ApiConfigModel>().init();
|
||||
}
|
||||
|
||||
Future<void> saveServerProviderType(final ServerProvider type) async {
|
||||
await getIt<ApiConfigModel>().storeServerProviderType(type);
|
||||
}
|
||||
|
||||
Future<void> saveServerProviderKey(final String key) async {
|
||||
await getIt<ApiConfigModel>().storeServerProviderKey(key);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ class ApiConfigModel {
|
|||
String? get serverLocation => _serverLocation;
|
||||
String? get serverType => _serverType;
|
||||
String? get cloudFlareKey => _cloudFlareKey;
|
||||
ServerProvider? get serverProvider => _serverProvider;
|
||||
BackblazeCredential? get backblazeCredential => _backblazeCredential;
|
||||
ServerDomain? get serverDomain => _serverDomain;
|
||||
BackblazeBucket? get backblazeBucket => _backblazeBucket;
|
||||
|
@ -21,11 +22,17 @@ class ApiConfigModel {
|
|||
String? _serverLocation;
|
||||
String? _cloudFlareKey;
|
||||
String? _serverType;
|
||||
ServerProvider? _serverProvider;
|
||||
ServerHostingDetails? _serverDetails;
|
||||
BackblazeCredential? _backblazeCredential;
|
||||
ServerDomain? _serverDomain;
|
||||
BackblazeBucket? _backblazeBucket;
|
||||
|
||||
Future<void> storeServerProviderType(final ServerProvider value) async {
|
||||
await _box.put(BNames.serverProvider, value);
|
||||
_serverProvider = value;
|
||||
}
|
||||
|
||||
Future<void> storeServerProviderKey(final String value) async {
|
||||
await _box.put(BNames.hetznerKey, value);
|
||||
_serverProviderKey = value;
|
||||
|
|
|
@ -72,7 +72,8 @@ class InitializingPage extends StatelessWidget {
|
|||
)
|
||||
: ProgressBar(
|
||||
steps: const [
|
||||
'Hetzner',
|
||||
'Hosting',
|
||||
'Server Type',
|
||||
'CloudFlare',
|
||||
'Backblaze',
|
||||
'Domain',
|
||||
|
|
|
@ -114,9 +114,7 @@ class ProviderInputDataPage extends StatelessWidget {
|
|||
const Spacer(),
|
||||
FilledButton(
|
||||
title: 'basis.connect'.tr(),
|
||||
onPressed: () => providerCubit.state.isSubmitting
|
||||
? null
|
||||
: () => providerCubit.trySubmit(),
|
||||
onPressed: () => providerCubit.trySubmit(),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
OutlinedButton(
|
||||
|
|
|
@ -147,14 +147,14 @@ class SelectTypePage extends StatelessWidget {
|
|||
children: [
|
||||
Text(type.title),
|
||||
const SizedBox(height: 8),
|
||||
Text('cores: $type.cores'),
|
||||
Text('cores: $type.cores.toString()'),
|
||||
const SizedBox(height: 8),
|
||||
Text('ram: $type.ram'),
|
||||
Text('ram: $type.ram.toString()'),
|
||||
const SizedBox(height: 8),
|
||||
Text('disk: $type.disk.gibibyte'),
|
||||
Text('disk: $type.disk.gibibyte.toString()'),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'price: $type.price.value $type.price.currency',
|
||||
'price: $type.price.value.toString() $type.price.currency',
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue