Merge branch 'master' into digital-ocean-dns

pull/213/head
NaiJi ✨ 2022-12-21 13:47:25 +04:00
commit 8922551239
6 changed files with 74 additions and 20 deletions

View File

@ -392,6 +392,7 @@
"generation_error": "Couldn't generate a recovery key. {}" "generation_error": "Couldn't generate a recovery key. {}"
}, },
"modals": { "modals": {
"server_validators_error": "Couldn't fetch available servers.",
"already_exists": "Such server already exists.", "already_exists": "Such server already exists.",
"unexpected_error": "Unexpected error during placement from the provider side.", "unexpected_error": "Unexpected error during placement from the provider side.",
"destroy_server": "Destroy the server and create a new one?", "destroy_server": "Destroy the server and create a new one?",

View File

@ -392,6 +392,7 @@
"generation_error": "Не удалось сгенерировать ключ. {}" "generation_error": "Не удалось сгенерировать ключ. {}"
}, },
"modals": { "modals": {
"server_validators_error": "Не удалось получить список серверов.",
"already_exists": "Такой сервер уже существует.", "already_exists": "Такой сервер уже существует.",
"unexpected_error": "Непредвиденная ошибка со стороны провайдера.", "unexpected_error": "Непредвиденная ошибка со стороны провайдера.",
"destroy_server": "Уничтожить сервер и создать новый?", "destroy_server": "Уничтожить сервер и создать новый?",

View File

@ -4,6 +4,42 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:http/io_client.dart'; import 'package:http/io_client.dart';
import 'package:selfprivacy/config/get_it_config.dart'; import 'package:selfprivacy/config/get_it_config.dart';
import 'package:selfprivacy/logic/api_maps/staging_options.dart'; import 'package:selfprivacy/logic/api_maps/staging_options.dart';
import 'package:selfprivacy/logic/models/message.dart';
void _logToAppConsole<T>(final T objectToLog) {
getIt.get<ConsoleModel>().addMessage(
Message(
text: objectToLog.toString(),
),
);
}
class RequestLoggingLink extends Link {
@override
Stream<Response> request(
final Request request, [
final NextLink? forward,
]) async* {
_logToAppConsole(request);
yield* forward!(request);
}
}
class ResponseLoggingParser extends ResponseParser {
@override
Response parseResponse(final Map<String, dynamic> body) {
final response = super.parseResponse(body);
_logToAppConsole(response);
return response;
}
@override
GraphQLError parseError(final Map<String, dynamic> error) {
final graphQlError = super.parseError(error);
_logToAppConsole(graphQlError);
return graphQlError;
}
}
abstract class ApiMap { abstract class ApiMap {
Future<GraphQLClient> getClient() async { Future<GraphQLClient> getClient() async {
@ -22,16 +58,23 @@ abstract class ApiMap {
final httpLink = HttpLink( final httpLink = HttpLink(
'https://api.$rootAddress/graphql', 'https://api.$rootAddress/graphql',
httpClient: ioClient, httpClient: ioClient,
parser: ResponseLoggingParser(),
); );
final String token = _getApiToken(); final String token = _getApiToken();
final Link graphQLLink = isWithToken final Link graphQLLink = RequestLoggingLink().concat(
isWithToken
? AuthLink( ? AuthLink(
getToken: () async => getToken: () async =>
customToken == '' ? 'Bearer $token' : customToken, customToken == '' ? 'Bearer $token' : customToken,
).concat(httpLink) ).concat(httpLink)
: httpLink; : httpLink,
);
// Every request goes through either chain:
// 1. RequestLoggingLink -> AuthLink -> HttpLink
// 2. RequestLoggingLink -> HttpLink
return GraphQLClient( return GraphQLClient(
cache: GraphQLCache(), cache: GraphQLCache(),

View File

@ -23,7 +23,7 @@ import 'package:selfprivacy/utils/password_generator.dart';
class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi { class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
DigitalOceanApi({ DigitalOceanApi({
required this.region, required this.region,
this.hasLogger = false, this.hasLogger = true,
this.isWithToken = true, this.isWithToken = true,
}); });
@override @override

View File

@ -24,7 +24,7 @@ import 'package:selfprivacy/utils/password_generator.dart';
class HetznerApi extends ServerProviderApi with VolumeProviderApi { class HetznerApi extends ServerProviderApi with VolumeProviderApi {
HetznerApi({ HetznerApi({
this.region, this.region,
this.hasLogger = false, this.hasLogger = true,
this.isWithToken = true, this.isWithToken = true,
}); });
@override @override

View File

@ -633,6 +633,8 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
state as ServerInstallationRecovery; state as ServerInstallationRecovery;
final List<ServerBasicInfo> servers = final List<ServerBasicInfo> servers =
await repository.getServersOnProviderAccount(); await repository.getServersOnProviderAccount();
List<ServerBasicInfoWithValidators> validatedList = [];
try {
final Iterable<ServerBasicInfoWithValidators> validated = servers.map( final Iterable<ServerBasicInfoWithValidators> validated = servers.map(
(final ServerBasicInfo server) => (final ServerBasicInfo server) =>
ServerBasicInfoWithValidators.fromServerBasicInfo( ServerBasicInfoWithValidators.fromServerBasicInfo(
@ -644,7 +646,14 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
dataState.serverDomain?.domainName.split('.')[0], dataState.serverDomain?.domainName.split('.')[0],
), ),
); );
return validated.toList(); validatedList = validated.toList();
} catch (e) {
print(e);
getIt<NavigationService>()
.showSnackBar('modals.server_validators_error'.tr());
}
return validatedList;
} }
Future<void> setServerId(final ServerBasicInfo server) async { Future<void> setServerId(final ServerBasicInfo server) async {