Fix dkim runtime exception

pull/111/head
NaiJi ✨ 2022-08-29 23:21:59 +03:00
parent d168845b98
commit 62929a4839
3 changed files with 19 additions and 31 deletions

View File

@ -625,38 +625,25 @@ class ServerApi extends ApiMap {
}
}
Future<String> getDkim() async {
Future<String?> getDkim() async {
Response response;
String? dkim;
final Dio client = await getClient();
try {
response = await client.get('/services/mailserver/dkim');
final Codec<String, String> 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<String, String> base64toString = utf8.fuse(base64);
return base64toString
.decode(response.data)
.split('(')[1]
.split(')')[0]
.replaceAll('"', '');
return dkim;
}
Future<ApiResponse<RecoveryKeyStatus?>> getRecoveryTokenStatus() async {

View File

@ -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,
),
];
}
}

View File

@ -398,7 +398,7 @@ class ServerInstallationRepository {
String dkimRecordString = '';
try {
dkimRecordString = await api.getDkim();
dkimRecordString = (await api.getDkim())!;
} catch (e) {
print(e);
rethrow;