mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 10:29:39 +00:00
Fix application failure on cloudflare 403 response
Check error response and show modal dialogue if domain couldn't be registered
This commit is contained in:
parent
129c1bb4c6
commit
10488d6832
|
@ -299,6 +299,7 @@
|
|||
"7": "Yes",
|
||||
"8": "Remove task",
|
||||
"9": "Reboot",
|
||||
"10": "You cannot use this API for domains with such TLD.",
|
||||
"yes": "Yes"
|
||||
},
|
||||
"timer": {
|
||||
|
|
|
@ -295,6 +295,7 @@
|
|||
"7": "Да, удалить",
|
||||
"8": "Удалить задачу",
|
||||
"9": "Перезагрузить",
|
||||
"10": "API не поддерживает домены с таким TLD.",
|
||||
"yes": "Да"
|
||||
},
|
||||
"timer": {
|
||||
|
|
|
@ -125,23 +125,25 @@ class CloudflareApi extends ApiMap {
|
|||
var domainName = cloudFlareDomain.domainName;
|
||||
var domainZoneId = cloudFlareDomain.zoneId;
|
||||
var listDnsRecords = projectDnsRecords(domainName, ip4);
|
||||
|
||||
var url = '$rootAddress/zones/$domainZoneId/dns_records';
|
||||
|
||||
var allCreateFutures = <Future>[];
|
||||
|
||||
var client = await getClient();
|
||||
|
||||
for (var record in listDnsRecords) {
|
||||
allCreateFutures.add(
|
||||
client.post(
|
||||
url,
|
||||
data: record.toJson(),
|
||||
),
|
||||
);
|
||||
try {
|
||||
for (var record in listDnsRecords) {
|
||||
allCreateFutures.add(
|
||||
client.post(
|
||||
'/zones/$domainZoneId/dns_records',
|
||||
data: record.toJson(),
|
||||
),
|
||||
);
|
||||
}
|
||||
await Future.wait(allCreateFutures);
|
||||
} on DioError catch (e) {
|
||||
print(e.message);
|
||||
throw e;
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
await Future.wait(allCreateFutures);
|
||||
close(client);
|
||||
}
|
||||
|
||||
List<DnsRecord> projectDnsRecords(String? domainName, String? ip4) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import 'package:selfprivacy/logic/models/json/recovery_token_status.dart';
|
|||
import 'package:selfprivacy/logic/models/json/device_token.dart';
|
||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:timezone/browser.dart';
|
||||
|
||||
import 'api_map.dart';
|
||||
|
||||
|
|
|
@ -80,10 +80,14 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
|||
|
||||
void createServerAndSetDnsRecords() async {
|
||||
AppConfigNotFinished _stateCopy = state as AppConfigNotFinished;
|
||||
var onCancel =
|
||||
() => emit((state as AppConfigNotFinished).copyWith(isLoading: false));
|
||||
|
||||
var onSuccess = (ServerHostingDetails serverDetails) async {
|
||||
await repository.createDnsRecords(
|
||||
serverDetails.ip4,
|
||||
state.serverDomain!,
|
||||
onCancel: onCancel,
|
||||
);
|
||||
|
||||
emit((state as AppConfigNotFinished).copyWith(
|
||||
|
@ -93,9 +97,6 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
|||
runDelayed(startServerIfDnsIsOkay, Duration(seconds: 30), null);
|
||||
};
|
||||
|
||||
var onCancel =
|
||||
() => emit((state as AppConfigNotFinished).copyWith(isLoading: false));
|
||||
|
||||
try {
|
||||
emit((state as AppConfigNotFinished).copyWith(isLoading: true));
|
||||
await repository.createServer(
|
||||
|
|
|
@ -214,8 +214,9 @@ class AppConfigRepository {
|
|||
|
||||
Future<void> createDnsRecords(
|
||||
String ip4,
|
||||
ServerDomain cloudFlareDomain,
|
||||
) async {
|
||||
ServerDomain cloudFlareDomain, {
|
||||
required void Function() onCancel,
|
||||
}) async {
|
||||
var cloudflareApi = CloudflareApi();
|
||||
|
||||
await cloudflareApi.removeSimilarRecords(
|
||||
|
@ -223,10 +224,41 @@ class AppConfigRepository {
|
|||
cloudFlareDomain: cloudFlareDomain,
|
||||
);
|
||||
|
||||
await cloudflareApi.createMultipleDnsRecords(
|
||||
ip4: ip4,
|
||||
cloudFlareDomain: cloudFlareDomain,
|
||||
);
|
||||
try {
|
||||
await cloudflareApi.createMultipleDnsRecords(
|
||||
ip4: ip4,
|
||||
cloudFlareDomain: cloudFlareDomain,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
var hetznerApi = HetznerApi();
|
||||
var nav = getIt.get<NavigationService>();
|
||||
nav.showPopUpDialog(
|
||||
BrandAlert(
|
||||
title: e.response!.data["errors"][0]["code"] == 1038
|
||||
? 'modals.10'.tr()
|
||||
: 'providers.domain.states.error'.tr(),
|
||||
contentText: 'modals.6'.tr(),
|
||||
actions: [
|
||||
ActionButton(
|
||||
text: 'basis.delete'.tr(),
|
||||
isRed: true,
|
||||
onPressed: () async {
|
||||
await hetznerApi.deleteSelfprivacyServerAndAllVolumes(
|
||||
domainName: cloudFlareDomain.domainName);
|
||||
|
||||
onCancel();
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
text: 'basis.cancel'.tr(),
|
||||
onPressed: () {
|
||||
onCancel();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
await HetznerApi().createReverseDns(
|
||||
ip4: ip4,
|
||||
|
|
Loading…
Reference in a new issue