mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 09:16:54 +00:00
chore: Implement basic DigitalOceanServerType model
This commit is contained in:
parent
8d8e8cf265
commit
f6424200e2
|
@ -326,7 +326,7 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
'image': 'ubuntu-20-04-x64',
|
||||
'user_data': '#cloud-config\n'
|
||||
'runcmd:\n'
|
||||
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/providers/digital-ocean/nixos-infect | '
|
||||
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/testing/final-digital-ocean/nixos-infect | '
|
||||
"PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType STAGING_ACME='$stagingAcme' DOMAIN='$domainName' "
|
||||
"LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' CF_TOKEN=$dnsApiToken DB_PASSWORD=$databasePassword "
|
||||
'API_TOKEN=$serverApiToken HOSTNAME=$hostName bash 2>&1 | tee /tmp/infect.log',
|
||||
|
@ -537,15 +537,18 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
return GenericResult(data: locations, success: true);
|
||||
}
|
||||
|
||||
Future<GenericResult<List>> getAvailableServerTypes() async {
|
||||
List types = [];
|
||||
Future<GenericResult<List<DigitalOceanServerType>>>
|
||||
getAvailableServerTypes() async {
|
||||
final List<DigitalOceanServerType> types = [];
|
||||
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
final Response response = await client.get(
|
||||
'/sizes',
|
||||
);
|
||||
types = response.data!['sizes'];
|
||||
for (final size in response.data!['sizes']) {
|
||||
types.add(DigitalOceanServerType.fromJson(size));
|
||||
}
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return GenericResult(
|
||||
|
|
|
@ -372,7 +372,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
'networks': [],
|
||||
'user_data': '#cloud-config\n'
|
||||
'runcmd:\n'
|
||||
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/providers/hetzner/nixos-infect | '
|
||||
'- curl https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-infect/raw/branch/testing/final-hetzner/nixos-infect | '
|
||||
"STAGING_ACME='$stagingAcme' PROVIDER=$infectProviderName DNS_PROVIDER_TYPE=$dnsProviderType "
|
||||
"NIX_CHANNEL=nixos-21.05 DOMAIN='$domainName' LUSER='${rootUser.login}' ENCODED_PASSWORD='$base64Password' "
|
||||
'CF_TOKEN=$dnsApiToken DB_PASSWORD=$databasePassword API_TOKEN=$serverApiToken HOSTNAME=$hostName bash 2>&1 | '
|
||||
|
|
|
@ -37,3 +37,29 @@ class DigitalOceanLocation {
|
|||
static DigitalOceanLocation fromJson(final Map<String, dynamic> json) =>
|
||||
_$DigitalOceanLocationFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class DigitalOceanServerType {
|
||||
DigitalOceanServerType(
|
||||
this.regions,
|
||||
this.memory,
|
||||
this.description,
|
||||
this.disk,
|
||||
this.priceMonthly,
|
||||
this.slug,
|
||||
this.vcpus,
|
||||
);
|
||||
|
||||
final List<String> regions;
|
||||
final double memory;
|
||||
final String slug;
|
||||
final String description;
|
||||
final int vcpus;
|
||||
final int disk;
|
||||
|
||||
@JsonKey(name: 'price_monthly')
|
||||
final double priceMonthly;
|
||||
|
||||
static DigitalOceanServerType fromJson(final Map<String, dynamic> json) =>
|
||||
_$DigitalOceanServerTypeFromJson(json);
|
||||
}
|
||||
|
|
|
@ -35,3 +35,27 @@ Map<String, dynamic> _$DigitalOceanLocationToJson(
|
|||
'slug': instance.slug,
|
||||
'name': instance.name,
|
||||
};
|
||||
|
||||
DigitalOceanServerType _$DigitalOceanServerTypeFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
DigitalOceanServerType(
|
||||
(json['regions'] as List<dynamic>).map((e) => e as String).toList(),
|
||||
(json['memory'] as num).toDouble(),
|
||||
json['description'] as String,
|
||||
json['disk'] as int,
|
||||
(json['price_monthly'] as num).toDouble(),
|
||||
json['slug'] as String,
|
||||
json['vcpus'] as int,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$DigitalOceanServerTypeToJson(
|
||||
DigitalOceanServerType instance) =>
|
||||
<String, dynamic>{
|
||||
'regions': instance.regions,
|
||||
'memory': instance.memory,
|
||||
'slug': instance.slug,
|
||||
'description': instance.description,
|
||||
'vcpus': instance.vcpus,
|
||||
'disk': instance.disk,
|
||||
'price_monthly': instance.priceMonthly,
|
||||
};
|
||||
|
|
|
@ -291,20 +291,19 @@ class DigitalOceanServerProvider extends ServerProvider {
|
|||
);
|
||||
}
|
||||
|
||||
final List rawSizes = result.data;
|
||||
final List<DigitalOceanServerType> rawSizes = result.data;
|
||||
for (final rawSize in rawSizes) {
|
||||
for (final rawRegion in rawSize['regions']) {
|
||||
final ramMb = rawSize['memory'].toDouble();
|
||||
if (rawRegion.toString() == location.identifier && ramMb > 1024) {
|
||||
for (final rawRegion in rawSize.regions) {
|
||||
if (rawRegion == location.identifier && rawSize.memory > 1024) {
|
||||
types.add(
|
||||
ServerType(
|
||||
title: rawSize['description'],
|
||||
identifier: rawSize['slug'],
|
||||
ram: ramMb / 1024,
|
||||
cores: rawSize['vcpus'],
|
||||
disk: DiskSize(byte: rawSize['disk'] * 1024 * 1024 * 1024),
|
||||
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['price_monthly'],
|
||||
value: rawSize.priceMonthly,
|
||||
currency: 'USD',
|
||||
),
|
||||
location: location,
|
||||
|
|
Loading…
Reference in a new issue