mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-09 01:21:14 +00:00
chore: Replace dynamic blobs with HetznerServerType
This commit is contained in:
parent
ffa13aee04
commit
2a66d246c7
|
@ -147,7 +147,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
'format': 'ext4'
|
'format': 'ext4'
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
volume = HetznerVolume.fromJson(createVolumeResponse.data);
|
volume = HetznerVolume.fromJson(createVolumeResponse.data['volume']);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
|
@ -167,8 +167,10 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GenericResult<List>> getVolumes({final String? status}) async {
|
Future<GenericResult<List<HetznerVolume>>> getVolumes({
|
||||||
List volumes = [];
|
final String? status,
|
||||||
|
}) async {
|
||||||
|
final List<HetznerVolume> volumes = [];
|
||||||
|
|
||||||
Response? getVolumesResonse;
|
Response? getVolumesResonse;
|
||||||
final Dio client = await getClient();
|
final Dio client = await getClient();
|
||||||
|
@ -179,7 +181,9 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
'status': status,
|
'status': status,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
volumes = getVolumesResonse.data['volumes'];
|
for (final volume in getVolumesResonse.data['volumes']) {
|
||||||
|
volumes.add(HetznerVolume.fromJson(volume));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
|
@ -199,34 +203,31 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<ServerVolume?> getVolume(
|
Future<GenericResult<HetznerVolume?>> getVolume(
|
||||||
final String volumeId,
|
final String volumeId,
|
||||||
) async {
|
) async {
|
||||||
ServerVolume? volume;
|
HetznerVolume? volume;
|
||||||
|
|
||||||
final Response getVolumeResponse;
|
final Response getVolumeResponse;
|
||||||
final Dio client = await getClient();
|
final Dio client = await getClient();
|
||||||
try {
|
try {
|
||||||
getVolumeResponse = await client.get('/volumes/$volumeId');
|
getVolumeResponse = await client.get('/volumes/$volumeId');
|
||||||
final int responseVolumeId = getVolumeResponse.data['volume']['id'];
|
volume = HetznerVolume.fromJson(getVolumeResponse.data['volume']);
|
||||||
final int volumeSize = getVolumeResponse.data['volume']['size'];
|
|
||||||
final int volumeServer = getVolumeResponse.data['volume']['server'];
|
|
||||||
final String volumeName = getVolumeResponse.data['volume']['name'];
|
|
||||||
final volumeDevice = getVolumeResponse.data['volume']['linux_device'];
|
|
||||||
volume = ServerVolume(
|
|
||||||
id: responseVolumeId,
|
|
||||||
name: volumeName,
|
|
||||||
sizeByte: volumeSize,
|
|
||||||
serverId: volumeServer,
|
|
||||||
linuxDevice: volumeDevice,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
|
return GenericResult(
|
||||||
|
data: null,
|
||||||
|
success: false,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
client.close();
|
client.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return volume;
|
return GenericResult(
|
||||||
|
data: volume,
|
||||||
|
success: true,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GenericResult<bool>> deleteVolume(final int volumeId) async {
|
Future<GenericResult<bool>> deleteVolume(final int volumeId) async {
|
||||||
|
@ -547,15 +548,18 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
return GenericResult(success: true, data: locations);
|
return GenericResult(success: true, data: locations);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<GenericResult<List>> getAvailableServerTypes() async {
|
Future<GenericResult<List<HetznerServerTypeInfo>>>
|
||||||
List types = [];
|
getAvailableServerTypes() async {
|
||||||
|
final List<HetznerServerTypeInfo> types = [];
|
||||||
|
|
||||||
final Dio client = await getClient();
|
final Dio client = await getClient();
|
||||||
try {
|
try {
|
||||||
final Response response = await client.get(
|
final Response response = await client.get(
|
||||||
'/server_types',
|
'/server_types',
|
||||||
);
|
);
|
||||||
types = response.data!['server_types'];
|
for (final type in response.data!['server_types']) {
|
||||||
|
types.add(HetznerServerTypeInfo.fromJson(type));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
return GenericResult(
|
return GenericResult(
|
||||||
|
|
|
@ -72,11 +72,21 @@ enum ServerStatus {
|
||||||
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class HetznerServerTypeInfo {
|
class HetznerServerTypeInfo {
|
||||||
HetznerServerTypeInfo(this.cores, this.memory, this.disk, this.prices);
|
HetznerServerTypeInfo(
|
||||||
|
this.cores,
|
||||||
|
this.memory,
|
||||||
|
this.disk,
|
||||||
|
this.prices,
|
||||||
|
this.name,
|
||||||
|
this.description,
|
||||||
|
);
|
||||||
final int cores;
|
final int cores;
|
||||||
final num memory;
|
final num memory;
|
||||||
final int disk;
|
final int disk;
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
final String description;
|
||||||
|
|
||||||
final List<HetznerPriceInfo> prices;
|
final List<HetznerPriceInfo> prices;
|
||||||
|
|
||||||
static HetznerServerTypeInfo fromJson(final Map<String, dynamic> json) =>
|
static HetznerServerTypeInfo fromJson(final Map<String, dynamic> json) =>
|
||||||
|
@ -85,7 +95,11 @@ class HetznerServerTypeInfo {
|
||||||
|
|
||||||
@JsonSerializable()
|
@JsonSerializable()
|
||||||
class HetznerPriceInfo {
|
class HetznerPriceInfo {
|
||||||
HetznerPriceInfo(this.hourly, this.monthly);
|
HetznerPriceInfo(
|
||||||
|
this.hourly,
|
||||||
|
this.monthly,
|
||||||
|
this.location,
|
||||||
|
);
|
||||||
|
|
||||||
@JsonKey(name: 'price_hourly', fromJson: HetznerPriceInfo.getPrice)
|
@JsonKey(name: 'price_hourly', fromJson: HetznerPriceInfo.getPrice)
|
||||||
final double hourly;
|
final double hourly;
|
||||||
|
@ -93,6 +107,8 @@ class HetznerPriceInfo {
|
||||||
@JsonKey(name: 'price_monthly', fromJson: HetznerPriceInfo.getPrice)
|
@JsonKey(name: 'price_monthly', fromJson: HetznerPriceInfo.getPrice)
|
||||||
final double monthly;
|
final double monthly;
|
||||||
|
|
||||||
|
final String location;
|
||||||
|
|
||||||
static HetznerPriceInfo fromJson(final Map<String, dynamic> json) =>
|
static HetznerPriceInfo fromJson(final Map<String, dynamic> json) =>
|
||||||
_$HetznerPriceInfoFromJson(json);
|
_$HetznerPriceInfoFromJson(json);
|
||||||
|
|
||||||
|
|
|
@ -150,19 +150,19 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final List rawTypes = result.data;
|
final rawTypes = result.data;
|
||||||
for (final rawType in rawTypes) {
|
for (final rawType in rawTypes) {
|
||||||
for (final rawPrice in rawType['prices']) {
|
for (final rawPrice in rawType.prices) {
|
||||||
if (rawPrice['location'].toString() == location.identifier) {
|
if (rawPrice.location == location.identifier) {
|
||||||
types.add(
|
types.add(
|
||||||
ServerType(
|
ServerType(
|
||||||
title: rawType['description'],
|
title: rawType.description,
|
||||||
identifier: rawType['name'],
|
identifier: rawType.name,
|
||||||
ram: rawType['memory'],
|
ram: rawType.memory.toDouble(),
|
||||||
cores: rawType['cores'],
|
cores: rawType.cores,
|
||||||
disk: DiskSize(byte: rawType['disk'] * 1024 * 1024 * 1024),
|
disk: DiskSize(byte: rawType.disk * 1024 * 1024 * 1024),
|
||||||
price: Price(
|
price: Price(
|
||||||
value: double.parse(rawPrice['price_monthly']['gross']),
|
value: rawPrice.monthly,
|
||||||
currency: 'EUR',
|
currency: 'EUR',
|
||||||
),
|
),
|
||||||
location: location,
|
location: location,
|
||||||
|
@ -532,7 +532,7 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
volume: ServerVolume(
|
volume: ServerVolume(
|
||||||
id: volume.id,
|
id: volume.id,
|
||||||
name: volume.name,
|
name: volume.name,
|
||||||
sizeByte: volume.sizeByte,
|
sizeByte: volume.sizeByte * 1024 * 1024 * 1024,
|
||||||
serverId: volume.serverId,
|
serverId: volume.serverId,
|
||||||
linuxDevice: volume.linuxDevice,
|
linuxDevice: volume.linuxDevice,
|
||||||
),
|
),
|
||||||
|
@ -676,7 +676,7 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
volume = ServerVolume(
|
volume = ServerVolume(
|
||||||
id: result.data!.id,
|
id: result.data!.id,
|
||||||
name: result.data!.name,
|
name: result.data!.name,
|
||||||
sizeByte: result.data!.sizeByte,
|
sizeByte: result.data!.sizeByte * 1024 * 1024 * 1024,
|
||||||
serverId: result.data!.serverId,
|
serverId: result.data!.serverId,
|
||||||
linuxDevice: result.data!.linuxDevice,
|
linuxDevice: result.data!.linuxDevice,
|
||||||
);
|
);
|
||||||
|
@ -716,11 +716,11 @@ class HetznerServerProvider extends ServerProvider {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (final rawVolume in result.data) {
|
for (final rawVolume in result.data) {
|
||||||
final int volumeId = rawVolume['id'];
|
final int volumeId = rawVolume.id;
|
||||||
final int volumeSize = rawVolume['size'] * 1024 * 1024 * 1024;
|
final int volumeSize = rawVolume.sizeByte * 1024 * 1024 * 1024;
|
||||||
final volumeServer = rawVolume['server'];
|
final volumeServer = rawVolume.serverId;
|
||||||
final String volumeName = rawVolume['name'];
|
final String volumeName = rawVolume.name;
|
||||||
final volumeDevice = rawVolume['linux_device'];
|
final volumeDevice = rawVolume.linuxDevice;
|
||||||
final volume = ServerVolume(
|
final volume = ServerVolume(
|
||||||
id: volumeId,
|
id: volumeId,
|
||||||
name: volumeName,
|
name: volumeName,
|
||||||
|
|
Loading…
Reference in a new issue