mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-23 01:06:44 +00:00
chore: Move domain list getter to dns provider layer for desec
This commit is contained in:
parent
4bb26559aa
commit
eebbf98349
|
@ -181,25 +181,35 @@ class DesecApi extends DnsProviderApi {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<List<String>> domainList() async {
|
||||
List<String> domains = [];
|
||||
Future<GenericResult<List>> getDomains() async {
|
||||
List domains = [];
|
||||
|
||||
late final Response? response;
|
||||
final Dio client = await getClient();
|
||||
try {
|
||||
final Response response = await client.get(
|
||||
response = await client.get(
|
||||
'',
|
||||
);
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
domains = response.data
|
||||
.map<String>((final el) => el['name'] as String)
|
||||
.toList();
|
||||
domains = response.data;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return GenericResult(
|
||||
success: false,
|
||||
data: domains,
|
||||
code: response?.statusCode,
|
||||
message: response?.statusMessage,
|
||||
);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return domains;
|
||||
return GenericResult(
|
||||
success: true,
|
||||
data: domains,
|
||||
code: response.statusCode,
|
||||
message: response.statusMessage,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -217,14 +217,10 @@ class DesecDnsProvider extends DnsProvider {
|
|||
],
|
||||
);
|
||||
|
||||
if (!result.success) {
|
||||
return GenericResult(
|
||||
success: result.success,
|
||||
data: null,
|
||||
code: result.code,
|
||||
message: result.message,
|
||||
);
|
||||
}
|
||||
return GenericResult(
|
||||
success: true,
|
||||
data: null,
|
||||
);
|
||||
}
|
||||
|
||||
String? extractContent(final DnsRecord record) {
|
||||
|
@ -235,4 +231,29 @@ class DesecDnsProvider extends DnsProvider {
|
|||
|
||||
return content;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<GenericResult<List<String>>> domainList() async {
|
||||
List<String> domains = [];
|
||||
final result = await _adapter.api().getDomains();
|
||||
if (result.data.isEmpty || !result.success) {
|
||||
return GenericResult(
|
||||
success: result.success,
|
||||
data: domains,
|
||||
code: result.code,
|
||||
message: result.message,
|
||||
);
|
||||
}
|
||||
|
||||
domains = result.data
|
||||
.map<String>(
|
||||
(final el) => el['name'] as String,
|
||||
)
|
||||
.toList();
|
||||
|
||||
return GenericResult(
|
||||
success: true,
|
||||
data: domains,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue