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. {}"
|
||||
},
|
||||
"modals": {
|
||||
"server_validators_error": "Couldn't fetch available servers.",
|
||||
"already_exists": "Such server already exists.",
|
||||
"unexpected_error": "Unexpected error during placement from the provider side.",
|
||||
"destroy_server": "Destroy the server and create a new one?",
|
||||
|
|
|
@ -392,6 +392,7 @@
|
|||
"generation_error": "Не удалось сгенерировать ключ. {}"
|
||||
},
|
||||
"modals": {
|
||||
"server_validators_error": "Не удалось получить список серверов.",
|
||||
"already_exists": "Такой сервер уже существует.",
|
||||
"unexpected_error": "Непредвиденная ошибка со стороны провайдера.",
|
||||
"destroy_server": "Уничтожить сервер и создать новый?",
|
||||
|
|
|
@ -4,6 +4,42 @@ import 'package:graphql_flutter/graphql_flutter.dart';
|
|||
import 'package:http/io_client.dart';
|
||||
import 'package:selfprivacy/config/get_it_config.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 {
|
||||
Future<GraphQLClient> getClient() async {
|
||||
|
@ -22,16 +58,23 @@ abstract class ApiMap {
|
|||
final httpLink = HttpLink(
|
||||
'https://api.$rootAddress/graphql',
|
||||
httpClient: ioClient,
|
||||
parser: ResponseLoggingParser(),
|
||||
);
|
||||
|
||||
final String token = _getApiToken();
|
||||
|
||||
final Link graphQLLink = isWithToken
|
||||
? AuthLink(
|
||||
getToken: () async =>
|
||||
customToken == '' ? 'Bearer $token' : customToken,
|
||||
).concat(httpLink)
|
||||
: httpLink;
|
||||
final Link graphQLLink = RequestLoggingLink().concat(
|
||||
isWithToken
|
||||
? AuthLink(
|
||||
getToken: () async =>
|
||||
customToken == '' ? 'Bearer $token' : customToken,
|
||||
).concat(httpLink)
|
||||
: httpLink,
|
||||
);
|
||||
|
||||
// Every request goes through either chain:
|
||||
// 1. RequestLoggingLink -> AuthLink -> HttpLink
|
||||
// 2. RequestLoggingLink -> HttpLink
|
||||
|
||||
return GraphQLClient(
|
||||
cache: GraphQLCache(),
|
||||
|
|
|
@ -23,7 +23,7 @@ import 'package:selfprivacy/utils/password_generator.dart';
|
|||
class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||
DigitalOceanApi({
|
||||
required this.region,
|
||||
this.hasLogger = false,
|
||||
this.hasLogger = true,
|
||||
this.isWithToken = true,
|
||||
});
|
||||
@override
|
||||
|
|
|
@ -24,7 +24,7 @@ import 'package:selfprivacy/utils/password_generator.dart';
|
|||
class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||
HetznerApi({
|
||||
this.region,
|
||||
this.hasLogger = false,
|
||||
this.hasLogger = true,
|
||||
this.isWithToken = true,
|
||||
});
|
||||
@override
|
||||
|
|
|
@ -633,18 +633,27 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
state as ServerInstallationRecovery;
|
||||
final List<ServerBasicInfo> servers =
|
||||
await repository.getServersOnProviderAccount();
|
||||
final Iterable<ServerBasicInfoWithValidators> validated = servers.map(
|
||||
(final ServerBasicInfo server) =>
|
||||
ServerBasicInfoWithValidators.fromServerBasicInfo(
|
||||
serverBasicInfo: server,
|
||||
isIpValid: server.ip == dataState.serverDetails?.ip4,
|
||||
isReverseDnsValid:
|
||||
server.reverseDns == dataState.serverDomain?.domainName ||
|
||||
server.reverseDns ==
|
||||
dataState.serverDomain?.domainName.split('.')[0],
|
||||
),
|
||||
);
|
||||
return validated.toList();
|
||||
List<ServerBasicInfoWithValidators> validatedList = [];
|
||||
try {
|
||||
final Iterable<ServerBasicInfoWithValidators> validated = servers.map(
|
||||
(final ServerBasicInfo server) =>
|
||||
ServerBasicInfoWithValidators.fromServerBasicInfo(
|
||||
serverBasicInfo: server,
|
||||
isIpValid: server.ip == dataState.serverDetails?.ip4,
|
||||
isReverseDnsValid:
|
||||
server.reverseDns == dataState.serverDomain?.domainName ||
|
||||
server.reverseDns ==
|
||||
dataState.serverDomain?.domainName.split('.')[0],
|
||||
),
|
||||
);
|
||||
validatedList = validated.toList();
|
||||
} catch (e) {
|
||||
print(e);
|
||||
getIt<NavigationService>()
|
||||
.showSnackBar('modals.server_validators_error'.tr());
|
||||
}
|
||||
|
||||
return validatedList;
|
||||
}
|
||||
|
||||
Future<void> setServerId(final ServerBasicInfo server) async {
|
||||
|
|
Loading…
Reference in a new issue