mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 18:39:45 +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",
|
"7": "Yes",
|
||||||
"8": "Remove task",
|
"8": "Remove task",
|
||||||
"9": "Reboot",
|
"9": "Reboot",
|
||||||
|
"10": "You cannot use this API for domains with such TLD.",
|
||||||
"yes": "Yes"
|
"yes": "Yes"
|
||||||
},
|
},
|
||||||
"timer": {
|
"timer": {
|
||||||
|
|
|
@ -295,6 +295,7 @@
|
||||||
"7": "Да, удалить",
|
"7": "Да, удалить",
|
||||||
"8": "Удалить задачу",
|
"8": "Удалить задачу",
|
||||||
"9": "Перезагрузить",
|
"9": "Перезагрузить",
|
||||||
|
"10": "API не поддерживает домены с таким TLD.",
|
||||||
"yes": "Да"
|
"yes": "Да"
|
||||||
},
|
},
|
||||||
"timer": {
|
"timer": {
|
||||||
|
|
|
@ -125,23 +125,25 @@ class CloudflareApi extends ApiMap {
|
||||||
var domainName = cloudFlareDomain.domainName;
|
var domainName = cloudFlareDomain.domainName;
|
||||||
var domainZoneId = cloudFlareDomain.zoneId;
|
var domainZoneId = cloudFlareDomain.zoneId;
|
||||||
var listDnsRecords = projectDnsRecords(domainName, ip4);
|
var listDnsRecords = projectDnsRecords(domainName, ip4);
|
||||||
|
|
||||||
var url = '$rootAddress/zones/$domainZoneId/dns_records';
|
|
||||||
|
|
||||||
var allCreateFutures = <Future>[];
|
var allCreateFutures = <Future>[];
|
||||||
|
|
||||||
var client = await getClient();
|
var client = await getClient();
|
||||||
|
try {
|
||||||
for (var record in listDnsRecords) {
|
for (var record in listDnsRecords) {
|
||||||
allCreateFutures.add(
|
allCreateFutures.add(
|
||||||
client.post(
|
client.post(
|
||||||
url,
|
'/zones/$domainZoneId/dns_records',
|
||||||
data: record.toJson(),
|
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) {
|
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/json/device_token.dart';
|
||||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:timezone/browser.dart';
|
|
||||||
|
|
||||||
import 'api_map.dart';
|
import 'api_map.dart';
|
||||||
|
|
||||||
|
|
|
@ -80,10 +80,14 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
|
|
||||||
void createServerAndSetDnsRecords() async {
|
void createServerAndSetDnsRecords() async {
|
||||||
AppConfigNotFinished _stateCopy = state as AppConfigNotFinished;
|
AppConfigNotFinished _stateCopy = state as AppConfigNotFinished;
|
||||||
|
var onCancel =
|
||||||
|
() => emit((state as AppConfigNotFinished).copyWith(isLoading: false));
|
||||||
|
|
||||||
var onSuccess = (ServerHostingDetails serverDetails) async {
|
var onSuccess = (ServerHostingDetails serverDetails) async {
|
||||||
await repository.createDnsRecords(
|
await repository.createDnsRecords(
|
||||||
serverDetails.ip4,
|
serverDetails.ip4,
|
||||||
state.serverDomain!,
|
state.serverDomain!,
|
||||||
|
onCancel: onCancel,
|
||||||
);
|
);
|
||||||
|
|
||||||
emit((state as AppConfigNotFinished).copyWith(
|
emit((state as AppConfigNotFinished).copyWith(
|
||||||
|
@ -93,9 +97,6 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
runDelayed(startServerIfDnsIsOkay, Duration(seconds: 30), null);
|
runDelayed(startServerIfDnsIsOkay, Duration(seconds: 30), null);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onCancel =
|
|
||||||
() => emit((state as AppConfigNotFinished).copyWith(isLoading: false));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
emit((state as AppConfigNotFinished).copyWith(isLoading: true));
|
emit((state as AppConfigNotFinished).copyWith(isLoading: true));
|
||||||
await repository.createServer(
|
await repository.createServer(
|
||||||
|
|
|
@ -214,8 +214,9 @@ class AppConfigRepository {
|
||||||
|
|
||||||
Future<void> createDnsRecords(
|
Future<void> createDnsRecords(
|
||||||
String ip4,
|
String ip4,
|
||||||
ServerDomain cloudFlareDomain,
|
ServerDomain cloudFlareDomain, {
|
||||||
) async {
|
required void Function() onCancel,
|
||||||
|
}) async {
|
||||||
var cloudflareApi = CloudflareApi();
|
var cloudflareApi = CloudflareApi();
|
||||||
|
|
||||||
await cloudflareApi.removeSimilarRecords(
|
await cloudflareApi.removeSimilarRecords(
|
||||||
|
@ -223,10 +224,41 @@ class AppConfigRepository {
|
||||||
cloudFlareDomain: cloudFlareDomain,
|
cloudFlareDomain: cloudFlareDomain,
|
||||||
);
|
);
|
||||||
|
|
||||||
await cloudflareApi.createMultipleDnsRecords(
|
try {
|
||||||
ip4: ip4,
|
await cloudflareApi.createMultipleDnsRecords(
|
||||||
cloudFlareDomain: cloudFlareDomain,
|
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(
|
await HetznerApi().createReverseDns(
|
||||||
ip4: ip4,
|
ip4: ip4,
|
||||||
|
|
Loading…
Reference in a new issue