diff --git a/lib/config/hive_config.dart b/lib/config/hive_config.dart index e010cfed..a5054674 100644 --- a/lib/config/hive_config.dart +++ b/lib/config/hive_config.dart @@ -115,10 +115,10 @@ class HiveConfig { /// add new migrations here, like: /// if (version < 3) {...}, etc. - - /// update saved version after successfull migrations - await localSettingsBox.put(BNames.databaseVersion, version); } + + /// update saved version after successfull migrations + await localSettingsBox.put(BNames.databaseVersion, version); } catch (error, stackTrace) { log( 'error running db migrations', diff --git a/lib/logic/cubit/server_installation/server_installation_cubit.dart b/lib/logic/cubit/server_installation/server_installation_cubit.dart index 6b507e93..4f1a52f3 100644 --- a/lib/logic/cubit/server_installation/server_installation_cubit.dart +++ b/lib/logic/cubit/server_installation/server_installation_cubit.dart @@ -794,13 +794,13 @@ class ServerInstallationCubit extends Cubit { await repository.saveIsServerStarted(true); await repository.saveIsServerRebootedFirstTime(true); await repository.saveIsServerRebootedSecondTime(true); - await repository.saveHasFinalChecked(true); await repository.saveIsRecoveringServer(false); final serverType = await ProvidersController.currentServerProvider! .getServerType(state.serverDetails!.id); await repository.saveServerType(serverType.data!); await ProvidersController.currentServerProvider! .trySetServerLocation(serverType.data!.location.identifier); + await repository.saveHasFinalChecked(true); final ServerInstallationRecovery updatedState = (state as ServerInstallationRecovery).copyWith( backblazeCredential: backblazeCredential, diff --git a/lib/logic/cubit/server_installation/server_installation_repository.dart b/lib/logic/cubit/server_installation/server_installation_repository.dart index 57b47c81..995e5922 100644 --- a/lib/logic/cubit/server_installation/server_installation_repository.dart +++ b/lib/logic/cubit/server_installation/server_installation_repository.dart @@ -182,6 +182,9 @@ class ServerInstallationRepository { if (!domainResult.success || domainResult.data.isEmpty) { return false; } + await getIt().removeDnsProviderToken( + getIt().dnsProviderCredentials.first, + ); return domainResult.data.any( (final serverDomain) => serverDomain.domainName == domain, @@ -519,6 +522,7 @@ class ServerInstallationRepository { // We are finished here. Time to save the state and finish the wizard // TODO: A lot of null checks are skipped here. Implication that every value exists might become false in the future. // TODO: We would actually want to handle token creation elsewhere. + await getIt().moveServerTypeToServerDetails(); final ServerInstallationWizardData wizardData = getIt().serverInstallation!; await getIt().addServer( diff --git a/lib/logic/get_it/resources_model.dart b/lib/logic/get_it/resources_model.dart index ebde7870..b2055381 100644 --- a/lib/logic/get_it/resources_model.dart +++ b/lib/logic/get_it/resources_model.dart @@ -78,6 +78,11 @@ class ResourcesModel { } Future addDnsProviderToken(final DnsProviderCredential token) async { + // Check if this token already exists + if (_dnsProviderTokens + .any((final credential) => credential.token == token.token)) { + throw Exception('Token already exists'); + } _dnsProviderTokens.add(token); await _box.put(BNames.dnsProviderTokens, _dnsProviderTokens); } @@ -227,10 +232,33 @@ class WizardDataModel { await _box.put(BNames.serverInstallationWizardData, _serverInstallation); } + Future moveServerTypeToServerDetails() async { + final details = _serverInstallation?.serverDetails; + if (details != null) { + if (_serverInstallation?.serverTypeIdentifier != null && + _serverInstallation?.serverLocation != null) { + _serverInstallation = _serverInstallation?.copyWith( + serverDetails: () => details.copyWith( + serverType: _serverInstallation?.serverTypeIdentifier, + serverLocation: _serverInstallation?.serverLocation, + ), + ); + await _box.put( + BNames.serverInstallationWizardData, + _serverInstallation, + ); + } + } + } + Future setServerDetails(final ServerHostingDetails details) async { + final detailsWithServerType = details.copyWith( + serverLocation: _serverInstallation?.serverLocation, + serverType: _serverInstallation?.serverTypeIdentifier, + ); _serverInstallation = (_serverInstallation ?? ServerInstallationWizardData.empty()) - .copyWith(serverDetails: () => details); + .copyWith(serverDetails: () => detailsWithServerType); await _box.put(BNames.serverInstallationWizardData, _serverInstallation); }