mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 18:39:45 +00:00
Merge branch 'master' into digital-ocean-dns
This commit is contained in:
commit
8922551239
|
@ -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?",
|
||||||
|
|
|
@ -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": "Уничтожить сервер и создать новый?",
|
||||||
|
|
|
@ -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(
|
||||||
? AuthLink(
|
isWithToken
|
||||||
getToken: () async =>
|
? AuthLink(
|
||||||
customToken == '' ? 'Bearer $token' : customToken,
|
getToken: () async =>
|
||||||
).concat(httpLink)
|
customToken == '' ? 'Bearer $token' : customToken,
|
||||||
: httpLink;
|
).concat(httpLink)
|
||||||
|
: httpLink,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Every request goes through either chain:
|
||||||
|
// 1. RequestLoggingLink -> AuthLink -> HttpLink
|
||||||
|
// 2. RequestLoggingLink -> HttpLink
|
||||||
|
|
||||||
return GraphQLClient(
|
return GraphQLClient(
|
||||||
cache: GraphQLCache(),
|
cache: GraphQLCache(),
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -633,18 +633,27 @@ 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();
|
||||||
final Iterable<ServerBasicInfoWithValidators> validated = servers.map(
|
List<ServerBasicInfoWithValidators> validatedList = [];
|
||||||
(final ServerBasicInfo server) =>
|
try {
|
||||||
ServerBasicInfoWithValidators.fromServerBasicInfo(
|
final Iterable<ServerBasicInfoWithValidators> validated = servers.map(
|
||||||
serverBasicInfo: server,
|
(final ServerBasicInfo server) =>
|
||||||
isIpValid: server.ip == dataState.serverDetails?.ip4,
|
ServerBasicInfoWithValidators.fromServerBasicInfo(
|
||||||
isReverseDnsValid:
|
serverBasicInfo: server,
|
||||||
server.reverseDns == dataState.serverDomain?.domainName ||
|
isIpValid: server.ip == dataState.serverDetails?.ip4,
|
||||||
server.reverseDns ==
|
isReverseDnsValid:
|
||||||
dataState.serverDomain?.domainName.split('.')[0],
|
server.reverseDns == dataState.serverDomain?.domainName ||
|
||||||
),
|
server.reverseDns ==
|
||||||
);
|
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 {
|
||||||
|
|
Loading…
Reference in a new issue