mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-16 05:33:17 +00:00
chore: Implement server installation on businness logic layer for hetzner
This commit is contained in:
parent
8da7341ccb
commit
ef04b5bf57
|
@ -172,7 +172,7 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
await repository.saveServerType(serverType);
|
||||
|
||||
await ProvidersController.currentServerProvider!
|
||||
.trySetServerLocation(serverType);
|
||||
.trySetServerLocation(serverType.identifier);
|
||||
|
||||
emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(
|
||||
|
@ -223,20 +223,11 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
emit((state as ServerInstallationNotFinished).copyWith(rootUser: rootUser));
|
||||
}
|
||||
|
||||
void createServerAndSetDnsRecords() async {
|
||||
final ServerInstallationNotFinished stateCopy =
|
||||
state as ServerInstallationNotFinished;
|
||||
void onCancel() => emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(isLoading: false),
|
||||
);
|
||||
|
||||
Future<void> onSuccess(final ServerHostingDetails serverDetails) async {
|
||||
await repository.createDnsRecords(
|
||||
serverDetails,
|
||||
state.serverDomain!,
|
||||
onCancel: onCancel,
|
||||
);
|
||||
|
||||
Future<void> onCreateServerSuccess(
|
||||
final ServerHostingDetails serverDetails,
|
||||
) async {
|
||||
await repository.saveServerDetails(serverDetails);
|
||||
// TODO dns;
|
||||
emit(
|
||||
(state as ServerInstallationNotFinished).copyWith(
|
||||
isLoading: false,
|
||||
|
@ -246,19 +237,16 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
|
|||
runDelayed(startServerIfDnsIsOkay, const Duration(seconds: 30), null);
|
||||
}
|
||||
|
||||
try {
|
||||
void createServerAndSetDnsRecords() async {
|
||||
emit((state as ServerInstallationNotFinished).copyWith(isLoading: true));
|
||||
await repository.createServer(
|
||||
state.rootUser!,
|
||||
state.serverDomain!.domainName,
|
||||
state.dnsApiToken!,
|
||||
state.backblazeCredential!,
|
||||
onCancel: onCancel,
|
||||
onSuccess: onSuccess,
|
||||
onCancel: clearAppConfig,
|
||||
onSuccess: onCreateServerSuccess,
|
||||
);
|
||||
} catch (e) {
|
||||
emit(stateCopy);
|
||||
}
|
||||
}
|
||||
|
||||
void startServerIfDnsIsOkay({
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||
import 'package:selfprivacy/logic/models/server_type.dart';
|
||||
|
@ -9,6 +10,8 @@ class LaunchInstallationData {
|
|||
required this.dnsProviderType,
|
||||
required this.domainName,
|
||||
required this.serverType,
|
||||
required this.errorCallback,
|
||||
required this.successCallback,
|
||||
});
|
||||
|
||||
final User rootUser;
|
||||
|
@ -16,4 +19,6 @@ class LaunchInstallationData {
|
|||
final String domainName;
|
||||
final DnsProviderType dnsProviderType;
|
||||
final ServerType serverType;
|
||||
final Function() errorCallback;
|
||||
final Function(ServerHostingDetails details) successCallback;
|
||||
}
|
||||
|
|
|
@ -424,7 +424,7 @@ class HetznerServerProvider extends ServerProvider {
|
|||
choices: [
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.cancel'.tr(),
|
||||
callback: null,
|
||||
callback: await installationData.errorCallback(),
|
||||
),
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.try_again'.tr(),
|
||||
|
@ -471,7 +471,7 @@ class HetznerServerProvider extends ServerProvider {
|
|||
choices: [
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.cancel'.tr(),
|
||||
callback: null,
|
||||
callback: installationData.errorCallback(),
|
||||
),
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.yes'.tr(),
|
||||
|
@ -498,7 +498,14 @@ class HetznerServerProvider extends ServerProvider {
|
|||
choices: [
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.cancel'.tr(),
|
||||
callback: null,
|
||||
callback: () async {
|
||||
final deletion = await deleteServer(hostname);
|
||||
if (deletion.success) {
|
||||
installationData.errorCallback();
|
||||
}
|
||||
|
||||
return deletion;
|
||||
},
|
||||
),
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.try_again'.tr(),
|
||||
|
@ -537,13 +544,23 @@ class HetznerServerProvider extends ServerProvider {
|
|||
choices: [
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.cancel'.tr(),
|
||||
callback: null,
|
||||
callback: () async {
|
||||
final deletion = await deleteServer(hostname);
|
||||
if (deletion.success) {
|
||||
installationData.errorCallback();
|
||||
}
|
||||
|
||||
return deletion;
|
||||
},
|
||||
),
|
||||
CallbackDialogueChoice(
|
||||
title: 'basis.try_again'.tr(),
|
||||
callback: () async {
|
||||
await _adapter.api().deleteVolume(volume);
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
final deletion = await deleteServer(hostname);
|
||||
if (deletion.success) {
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
return launchInstallation(installationData);
|
||||
}
|
||||
|
||||
|
@ -559,6 +576,9 @@ class HetznerServerProvider extends ServerProvider {
|
|||
code: volumeResult.code,
|
||||
);
|
||||
}
|
||||
|
||||
await installationData.successCallback(serverDetails);
|
||||
return GenericResult(success: true, data: null);
|
||||
}
|
||||
|
||||
Future<GenericResult<CallbackDialogueBranching?>> deleteServer(
|
||||
|
|
Loading…
Reference in a new issue