fix: App didn't save the server type and location correctly

This commit is contained in:
Inex Code 2024-07-04 18:05:01 +04:00
parent ad910d564a
commit 1ad8fccbb6
4 changed files with 37 additions and 5 deletions

View file

@ -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',

View file

@ -794,13 +794,13 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
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,

View file

@ -182,6 +182,9 @@ class ServerInstallationRepository {
if (!domainResult.success || domainResult.data.isEmpty) {
return false;
}
await getIt<ResourcesModel>().removeDnsProviderToken(
getIt<ResourcesModel>().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<WizardDataModel>().moveServerTypeToServerDetails();
final ServerInstallationWizardData wizardData =
getIt<WizardDataModel>().serverInstallation!;
await getIt<ResourcesModel>().addServer(

View file

@ -78,6 +78,11 @@ class ResourcesModel {
}
Future<void> 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<void> 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<void> 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);
}