chore: Replace dynamic blobs with HetznerLocation

pull/213/head
NaiJi ✨ 2023-06-07 00:25:34 -03:00
parent 875a9e2e86
commit f42e415633
3 changed files with 19 additions and 13 deletions

View File

@ -526,16 +526,15 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
return GenericResult(data: servers, success: true); return GenericResult(data: servers, success: true);
} }
Future<GenericResult<List>> getAvailableLocations() async { Future<GenericResult<List<HetznerLocation>>> getAvailableLocations() async {
List locations = []; final List<HetznerLocation> locations = [];
final Dio client = await getClient(); final Dio client = await getClient();
try { try {
final Response response = await client.get( final Response response = await client.get('/locations');
'/locations', for (final location in response.data!['locations']) {
); locations.add(HetznerLocation.fromJson(location));
}
locations = response.data!['locations'];
} catch (e) { } catch (e) {
print(e); print(e);
return GenericResult( return GenericResult(

View File

@ -118,7 +118,14 @@ class HetznerPriceInfo {
@JsonSerializable() @JsonSerializable()
class HetznerLocation { class HetznerLocation {
HetznerLocation(this.country, this.city, this.description, this.zone); HetznerLocation(
this.country,
this.city,
this.description,
this.zone,
this.name,
);
final String name;
final String country; final String country;
final String city; final String city;
final String description; final String description;

View File

@ -116,15 +116,15 @@ class HetznerServerProvider extends ServerProvider {
); );
} }
final List rawLocations = result.data; final List<HetznerLocation> rawLocations = result.data;
for (final rawLocation in rawLocations) { for (final rawLocation in rawLocations) {
ServerProviderLocation? location; ServerProviderLocation? location;
try { try {
location = ServerProviderLocation( location = ServerProviderLocation(
title: rawLocation['city'], title: rawLocation.city,
description: rawLocation['description'], description: rawLocation.description,
flag: getEmojiFlag(rawLocation['country']), flag: getEmojiFlag(rawLocation.country),
identifier: rawLocation['name'], identifier: rawLocation.name,
); );
} catch (e) { } catch (e) {
continue; continue;