From 62929a4839d0e8099c5892b6bd985dfb4386070b Mon Sep 17 00:00:00 2001 From: NaiJi Date: Mon, 29 Aug 2022 23:21:59 +0300 Subject: [PATCH] Fix dkim runtime exception --- lib/logic/api_maps/rest_maps/server.dart | 31 ++++++------------- .../cubit/dns_records/dns_records_cubit.dart | 17 +++++----- .../server_installation_repository.dart | 2 +- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/lib/logic/api_maps/rest_maps/server.dart b/lib/logic/api_maps/rest_maps/server.dart index 17c1cbb2..cd8e0a84 100644 --- a/lib/logic/api_maps/rest_maps/server.dart +++ b/lib/logic/api_maps/rest_maps/server.dart @@ -625,38 +625,25 @@ class ServerApi extends ApiMap { } } - Future getDkim() async { + Future getDkim() async { Response response; - + String? dkim; final Dio client = await getClient(); try { response = await client.get('/services/mailserver/dkim'); + final Codec base64toString = utf8.fuse(base64); + dkim = base64toString + .decode(response.data) + .split('(')[1] + .split(')')[0] + .replaceAll('"', ''); } on DioError catch (e) { print(e.message); - throw Exception('No DKIM key found'); } finally { close(client); } - if (response.statusCode == null) { - throw Exception('No DKIM key found'); - } - - if (response.statusCode == HttpStatus.notFound || response.data == null) { - throw Exception('No DKIM key found'); - } - - if (response.statusCode != HttpStatus.ok) { - throw Exception('No DKIM key found'); - } - - final Codec base64toString = utf8.fuse(base64); - - return base64toString - .decode(response.data) - .split('(')[1] - .split(')')[0] - .replaceAll('"', ''); + return dkim; } Future> getRecoveryTokenStatus() async { diff --git a/lib/logic/cubit/dns_records/dns_records_cubit.dart b/lib/logic/cubit/dns_records/dns_records_cubit.dart index e0ab4d42..93ff3db8 100644 --- a/lib/logic/cubit/dns_records/dns_records_cubit.dart +++ b/lib/logic/cubit/dns_records/dns_records_cubit.dart @@ -139,7 +139,7 @@ class DnsRecordsCubit final String? ipAddress, final String? dkimPublicKey, ) { - if (domainName == null || ipAddress == null || dkimPublicKey == null) { + if (domainName == null || ipAddress == null) { return []; } return [ @@ -204,13 +204,14 @@ class DnsRecordsCubit type: 'TXT', category: DnsRecordsCategory.email, ), - DesiredDnsRecord( - name: 'selector._domainkey.$domainName', - content: dkimPublicKey, - description: 'providers.domain.record_description.dkim', - type: 'TXT', - category: DnsRecordsCategory.email, - ), + if (dkimPublicKey != null) + DesiredDnsRecord( + name: 'selector._domainkey.$domainName', + content: dkimPublicKey, + description: 'providers.domain.record_description.dkim', + type: 'TXT', + category: DnsRecordsCategory.email, + ), ]; } } diff --git a/lib/logic/cubit/server_installation/server_installation_repository.dart b/lib/logic/cubit/server_installation/server_installation_repository.dart index cbf9ec61..c9ca0e96 100644 --- a/lib/logic/cubit/server_installation/server_installation_repository.dart +++ b/lib/logic/cubit/server_installation/server_installation_repository.dart @@ -398,7 +398,7 @@ class ServerInstallationRepository { String dkimRecordString = ''; try { - dkimRecordString = await api.getDkim(); + dkimRecordString = (await api.getDkim())!; } catch (e) { print(e); rethrow;