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');
} 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); final Codec<String, String> base64toString = utf8.fuse(base64);
dkim = base64toString
return base64toString
.decode(response.data) .decode(response.data)
.split('(')[1] .split('(')[1]
.split(')')[0] .split(')')[0]
.replaceAll('"', ''); .replaceAll('"', '');
} on DioError catch (e) {
print(e.message);
} finally {
close(client);
}
return dkim;
} }
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,6 +204,7 @@ class DnsRecordsCubit
type: 'TXT', type: 'TXT',
category: DnsRecordsCategory.email, category: DnsRecordsCategory.email,
), ),
if (dkimPublicKey != null)
DesiredDnsRecord( DesiredDnsRecord(
name: 'selector._domainkey.$domainName', name: 'selector._domainkey.$domainName',
content: dkimPublicKey, content: dkimPublicKey,

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;