mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
fix: Adapt usage of DNS provider interface to refactoring
This commit is contained in:
parent
b0769b8ed0
commit
d114d1477f
|
@ -19,7 +19,6 @@ class DigitalOceanDnsApi extends DnsProviderApi {
|
|||
|
||||
final String? customToken;
|
||||
|
||||
@override
|
||||
RegExp getApiTokenValidation() =>
|
||||
RegExp(r'\s+|[!$%^&*()@+|~=`{}\[\]:<>?,.\/]');
|
||||
|
||||
|
@ -45,7 +44,6 @@ class DigitalOceanDnsApi extends DnsProviderApi {
|
|||
@override
|
||||
String rootAddress = 'https://api.digitalocean.com/v2';
|
||||
|
||||
@override
|
||||
Future<GenericResult<bool>> isApiTokenValid(final String token) async {
|
||||
bool isValid = false;
|
||||
Response? response;
|
||||
|
|
|
@ -25,14 +25,13 @@ class DnsRecordsCubit
|
|||
emit(
|
||||
DnsRecordsState(
|
||||
dnsState: DnsRecordsStatus.refreshing,
|
||||
dnsRecords: ApiController.currentDnsProviderApiFactory
|
||||
?.getDnsProvider()
|
||||
.getDesiredDnsRecords(
|
||||
dnsRecords:
|
||||
ProvidersController.currentDnsProvider?.getDesiredDnsRecords(
|
||||
serverInstallationCubit.state.serverDomain?.domainName,
|
||||
'',
|
||||
'',
|
||||
) ??
|
||||
[],
|
||||
[],
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -45,13 +44,12 @@ class DnsRecordsCubit
|
|||
return;
|
||||
}
|
||||
|
||||
final foundRecords = await ApiController.currentDnsProviderApiFactory!
|
||||
.getDnsProvider()
|
||||
.validateDnsRecords(
|
||||
domain!,
|
||||
ipAddress!,
|
||||
extractDkimRecord(await api.getDnsRecords())?.content ?? '',
|
||||
);
|
||||
final foundRecords =
|
||||
await ProvidersController.currentDnsProvider!.validateDnsRecords(
|
||||
domain!,
|
||||
ipAddress!,
|
||||
extractDkimRecord(await api.getDnsRecords())?.content ?? '',
|
||||
);
|
||||
|
||||
if (!foundRecords.success || foundRecords.data.isEmpty) {
|
||||
emit(const DnsRecordsState());
|
||||
|
@ -89,10 +87,10 @@ class DnsRecordsCubit
|
|||
emit(state.copyWith(dnsState: DnsRecordsStatus.refreshing));
|
||||
final ServerDomain? domain = serverInstallationCubit.state.serverDomain;
|
||||
final String? ipAddress = serverInstallationCubit.state.serverDetails?.ip4;
|
||||
await ProvidersController.currentDnsProvider!.removeSimilarRecords(
|
||||
await ProvidersController.currentDnsProvider!.removeDomainRecords(
|
||||
domain: domain!,
|
||||
);
|
||||
await ProvidersController.currentDnsProvider!.createMultipleDnsRecords(
|
||||
await ProvidersController.currentDnsProvider!.createDomainRecords(
|
||||
domain: domain,
|
||||
ip4: ipAddress,
|
||||
);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:cubit_form/cubit_form.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/generic_result.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/providers/providers_controller.dart';
|
||||
|
@ -10,12 +11,12 @@ class DomainSetupCubit extends Cubit<DomainSetupState> {
|
|||
|
||||
Future<void> load() async {
|
||||
emit(Loading(LoadingTypes.loadingDomain));
|
||||
final List<String> list =
|
||||
final GenericResult<List<String>> result =
|
||||
await ProvidersController.currentDnsProvider!.domainList();
|
||||
if (list.isEmpty) {
|
||||
if (!result.success || result.data.isEmpty) {
|
||||
emit(Empty());
|
||||
} else if (list.length == 1) {
|
||||
emit(Loaded(list.first));
|
||||
} else if (result.data.length == 1) {
|
||||
emit(Loaded(result.data.first));
|
||||
} else {
|
||||
emit(MoreThenOne());
|
||||
}
|
||||
|
@ -27,13 +28,13 @@ class DomainSetupCubit extends Cubit<DomainSetupState> {
|
|||
|
||||
emit(Loading(LoadingTypes.saving));
|
||||
|
||||
final String? zoneId =
|
||||
final GenericResult<String?> zoneIdResult =
|
||||
await ProvidersController.currentDnsProvider!.getZoneId(domainName);
|
||||
|
||||
if (zoneId != null) {
|
||||
if (zoneIdResult.success || zoneIdResult.data != null) {
|
||||
final ServerDomain domain = ServerDomain(
|
||||
domainName: domainName,
|
||||
zoneId: zoneId,
|
||||
zoneId: zoneIdResult.data!,
|
||||
provider: DnsProviderType.cloudflare,
|
||||
);
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ import 'package:selfprivacy/logic/models/callback_dialogue_branching.dart';
|
|||
import 'package:selfprivacy/logic/models/launch_installation_data.dart';
|
||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/providers/providers_controller.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/server_providers/server_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
|
@ -258,7 +256,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
);
|
||||
|
||||
if (!result.success && result.data != null) {
|
||||
bool dialoguesResolved = false;
|
||||
CallbackDialogueBranching branching = result.data!;
|
||||
//while (!dialoguesResolved) {
|
||||
showPopUpAlert(
|
||||
|
@ -268,7 +265,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
actionButtonOnPressed: () async {
|
||||
final branchingResult = await branching.choices[1].callback!();
|
||||
if (branchingResult.data == null) {
|
||||
dialoguesResolved = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -278,7 +274,6 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
cancelButtonOnPressed: () async {
|
||||
final branchingResult = await branching.choices[0].callback!();
|
||||
if (branchingResult.data == null) {
|
||||
dialoguesResolved = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
|||
import 'package:selfprivacy/config/hive_config.dart';
|
||||
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||
import 'package:selfprivacy/logic/providers/provider_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/rest_maps/dns_providers/dns_provider_api_settings.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart';
|
||||
import 'package:selfprivacy/logic/api_maps/staging_options.dart';
|
||||
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
||||
|
@ -173,16 +171,14 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
Future<String?> getDomainId(final String token, final String domain) async {
|
||||
final DnsProviderApi dnsProviderApi =
|
||||
ApiController.currentDnsProviderApiFactory!.getDnsProvider(
|
||||
settings: DnsProviderApiSettings(
|
||||
isWithToken: false,
|
||||
customToken: token,
|
||||
),
|
||||
);
|
||||
|
||||
final String? domainId = await dnsProviderApi.getZoneId(domain);
|
||||
return domainId;
|
||||
final result =
|
||||
await ProvidersController.currentDnsProvider!.tryInitApiByToken(token);
|
||||
return result.success
|
||||
? (await ProvidersController.currentDnsProvider!.getZoneId(
|
||||
domain,
|
||||
))
|
||||
.data
|
||||
: null;
|
||||
}
|
||||
|
||||
Future<Map<String, bool>> isDnsAddressesMatch(
|
||||
|
@ -257,7 +253,7 @@ class ServerInstallationRepository {
|
|||
}
|
||||
|
||||
final GenericResult removingResult =
|
||||
await ProvidersController.currentDnsProvider!.removeSimilarRecords(
|
||||
await ProvidersController.currentDnsProvider!.removeDomainRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: domain,
|
||||
);
|
||||
|
@ -270,9 +266,8 @@ class ServerInstallationRepository {
|
|||
bool createdSuccessfully = false;
|
||||
String errorMessage = 'domain.error'.tr();
|
||||
try {
|
||||
final GenericResult createResult = await ProvidersController
|
||||
.currentDnsProvider!
|
||||
.createMultipleDnsRecords(
|
||||
final GenericResult createResult =
|
||||
await ProvidersController.currentDnsProvider!.createDomainRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: domain,
|
||||
);
|
||||
|
@ -605,10 +600,6 @@ class ServerInstallationRepository {
|
|||
getIt<ApiConfigModel>().init();
|
||||
}
|
||||
|
||||
Future<void> saveDnsProviderType(final DnsProvider type) async {
|
||||
await getIt<ApiConfigModel>().storeDnsProviderType(type);
|
||||
}
|
||||
|
||||
Future<void> saveBackblazeKey(
|
||||
final BackblazeCredential backblazeCredential,
|
||||
) async {
|
||||
|
@ -683,7 +674,7 @@ class ServerInstallationRepository {
|
|||
|
||||
final GenericResult<void> removalResult = await ProvidersController
|
||||
.currentDnsProvider!
|
||||
.removeSimilarRecords(domain: serverDomain);
|
||||
.removeDomainRecords(domain: serverDomain);
|
||||
|
||||
if (!removalResult.success) {
|
||||
getIt<NavigationService>().showSnackBar('modals.dns_removal_error'.tr());
|
||||
|
|
|
@ -580,11 +580,11 @@ class HetznerServerProvider extends ServerProvider {
|
|||
}
|
||||
|
||||
await installationData.successCallback(serverDetails);
|
||||
await installationData.dnsProvider.removeSimilarRecords(
|
||||
await installationData.dnsProvider.removeDomainRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: installationData.serverDomain,
|
||||
);
|
||||
await installationData.dnsProvider.createMultipleDnsRecords(
|
||||
await installationData.dnsProvider.createDomainRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: installationData.serverDomain,
|
||||
);
|
||||
|
|
|
@ -10,8 +10,6 @@ import 'package:selfprivacy/ui/components/brand_md/brand_md.dart';
|
|||
import 'package:selfprivacy/ui/components/buttons/brand_button.dart';
|
||||
import 'package:selfprivacy/ui/components/buttons/outlined_button.dart';
|
||||
import 'package:selfprivacy/ui/components/cards/outlined_card.dart';
|
||||
import 'package:selfprivacy/utils/network_utils.dart';
|
||||
import 'package:selfprivacy/utils/launch_url.dart';
|
||||
import 'package:url_launcher/url_launcher_string.dart';
|
||||
|
||||
class DnsProviderPicker extends StatefulWidget {
|
||||
|
|
|
@ -19,51 +19,45 @@ class RecoveryServerProviderConnected extends StatelessWidget {
|
|||
create: (final BuildContext context) =>
|
||||
ServerProviderFormCubit(appConfig),
|
||||
child: Builder(
|
||||
builder: (final BuildContext context) {
|
||||
final FormCubitState formCubitState =
|
||||
context.watch<ServerProviderFormCubit>().state;
|
||||
|
||||
return BrandHeroScreen(
|
||||
heroTitle: 'recovering.server_provider_connected'.tr(),
|
||||
heroSubtitle: 'recovering.server_provider_connected_description'.tr(
|
||||
args: [appConfig.state.serverDomain?.domainName ?? 'your domain'],
|
||||
builder: (final BuildContext context) => BrandHeroScreen(
|
||||
heroTitle: 'recovering.server_provider_connected'.tr(),
|
||||
heroSubtitle: 'recovering.server_provider_connected_description'.tr(
|
||||
args: [appConfig.state.serverDomain?.domainName ?? 'your domain'],
|
||||
),
|
||||
hasBackButton: true,
|
||||
hasFlashButton: false,
|
||||
ignoreBreakpoints: true,
|
||||
hasSupportDrawer: true,
|
||||
onBackButtonPressed: () {
|
||||
Navigator.of(context).popUntil((final route) => route.isFirst);
|
||||
},
|
||||
children: [
|
||||
CubitFormTextField(
|
||||
formFieldCubit: context.read<ServerProviderFormCubit>().apiKey,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText:
|
||||
'recovering.server_provider_connected_placeholder'.tr(),
|
||||
),
|
||||
),
|
||||
hasBackButton: true,
|
||||
hasFlashButton: false,
|
||||
ignoreBreakpoints: true,
|
||||
hasSupportDrawer: true,
|
||||
onBackButtonPressed: () {
|
||||
Navigator.of(context).popUntil((final route) => route.isFirst);
|
||||
},
|
||||
children: [
|
||||
CubitFormTextField(
|
||||
formFieldCubit: context.read<ServerProviderFormCubit>().apiKey,
|
||||
decoration: InputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
labelText:
|
||||
'recovering.server_provider_connected_placeholder'.tr(),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
BrandButton.filled(
|
||||
onPressed: () =>
|
||||
context.read<ServerProviderFormCubit>().trySubmit(),
|
||||
child: Text('basis.continue'.tr()),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Builder(
|
||||
builder: (final context) => BrandButton.text(
|
||||
title: 'initializing.how'.tr(),
|
||||
onPressed: () => context.read<SupportSystemCubit>().showArticle(
|
||||
article: 'how_hetzner',
|
||||
context: context,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
BrandButton.filled(
|
||||
onPressed: () =>
|
||||
context.read<ServerProviderFormCubit>().trySubmit(),
|
||||
child: Text('basis.continue'.tr()),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Builder(
|
||||
builder: (final context) => BrandButton.text(
|
||||
title: 'initializing.how'.tr(),
|
||||
onPressed: () =>
|
||||
context.read<SupportSystemCubit>().showArticle(
|
||||
article: 'how_hetzner',
|
||||
context: context,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue