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; Response response;
String? dkim;
final Dio client = await getClient(); final Dio client = await getClient();
try { try {
response = await client.get('/services/mailserver/dkim'); 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) { } on DioError catch (e) {
print(e.message); print(e.message);
throw Exception('No DKIM key found');
} finally { } finally {
close(client); close(client);
} }
if (response.statusCode == null) { return dkim;
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('"', '');
} }
Future<ApiResponse<RecoveryKeyStatus?>> getRecoveryTokenStatus() async { Future<ApiResponse<RecoveryKeyStatus?>> getRecoveryTokenStatus() async {

View File

@ -139,7 +139,7 @@ class DnsRecordsCubit
final String? ipAddress, final String? ipAddress,
final String? dkimPublicKey, final String? dkimPublicKey,
) { ) {
if (domainName == null || ipAddress == null || dkimPublicKey == null) { if (domainName == null || ipAddress == null) {
return []; return [];
} }
return [ return [
@ -204,13 +204,14 @@ class DnsRecordsCubit
type: 'TXT', type: 'TXT',
category: DnsRecordsCategory.email, category: DnsRecordsCategory.email,
), ),
DesiredDnsRecord( if (dkimPublicKey != null)
name: 'selector._domainkey.$domainName', DesiredDnsRecord(
content: dkimPublicKey, name: 'selector._domainkey.$domainName',
description: 'providers.domain.record_description.dkim', content: dkimPublicKey,
type: 'TXT', description: 'providers.domain.record_description.dkim',
category: DnsRecordsCategory.email, type: 'TXT',
), category: DnsRecordsCategory.email,
),
]; ];
} }
} }

View File

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