selfprivacy.org.app/lib/logic/cubit/server_installation/server_installation_state.dart

354 lines
10 KiB
Dart
Raw Normal View History

part of '../server_installation/server_installation_cubit.dart';
2021-01-06 19:35:57 +02:00
abstract class ServerInstallationState extends Equatable {
const ServerInstallationState({
2021-03-15 17:39:44 +02:00
required this.hetznerKey,
required this.cloudFlareKey,
required this.backblazeCredential,
required this.serverDomain,
2021-03-15 17:39:44 +02:00
required this.rootUser,
required this.serverDetails,
2021-03-15 17:39:44 +02:00
required this.isServerStarted,
2021-03-31 14:37:39 +03:00
required this.isServerResetedFirstTime,
required this.isServerResetedSecondTime,
2021-01-06 19:35:57 +02:00
});
@override
2021-03-15 17:39:44 +02:00
List<Object?> get props => [
2021-01-06 19:35:57 +02:00
hetznerKey,
cloudFlareKey,
2021-02-03 22:26:38 +02:00
backblazeCredential,
serverDomain,
2021-01-06 19:35:57 +02:00
rootUser,
serverDetails,
2021-02-16 20:48:15 +02:00
isServerStarted,
2021-03-31 14:37:39 +03:00
isServerResetedFirstTime,
2021-01-06 19:35:57 +02:00
];
2021-03-15 17:39:44 +02:00
final String? hetznerKey;
final String? cloudFlareKey;
final BackblazeCredential? backblazeCredential;
final ServerDomain? serverDomain;
2021-03-15 17:39:44 +02:00
final User? rootUser;
final ServerHostingDetails? serverDetails;
2021-03-23 21:50:11 +02:00
final bool isServerStarted;
2021-03-31 14:37:39 +03:00
final bool isServerResetedFirstTime;
final bool isServerResetedSecondTime;
2021-01-06 19:35:57 +02:00
bool get isHetznerFilled => hetznerKey != null;
bool get isCloudFlareFilled => cloudFlareKey != null;
2021-02-03 22:26:38 +02:00
bool get isBackblazeFilled => backblazeCredential != null;
bool get isDomainFilled => serverDomain != null;
2021-01-06 19:35:57 +02:00
bool get isUserFilled => rootUser != null;
bool get isServerCreated => serverDetails != null;
2021-01-21 23:01:42 +02:00
2021-10-14 00:49:24 +03:00
bool get isFullyInitilized => _fulfilementList.every((el) => el!);
ServerSetupProgress get progress =>
ServerSetupProgress.values[_fulfilementList.where((el) => el!).length];
2021-06-21 00:08:52 +03:00
int get porgressBar {
if (progress.index < 6) {
return progress.index;
} else if (progress.index < 10) {
2021-06-21 00:08:52 +03:00
return 6;
} else {
return 7;
}
}
2021-01-06 19:35:57 +02:00
2021-03-25 10:32:00 +02:00
List<bool?> get _fulfilementList {
var res = [
isHetznerFilled,
isCloudFlareFilled,
isBackblazeFilled,
isDomainFilled,
isUserFilled,
isServerCreated,
isServerStarted,
2021-03-31 14:37:39 +03:00
isServerResetedFirstTime,
isServerResetedSecondTime,
2021-03-25 10:32:00 +02:00
];
2021-03-30 20:38:40 +03:00
2021-03-25 10:32:00 +02:00
return res;
}
2021-01-06 19:35:57 +02:00
}
class TimerState extends ServerInstallationNotFinished {
2021-02-15 20:58:29 +02:00
TimerState({
2021-03-15 17:39:44 +02:00
required this.dataState,
2021-02-15 20:58:29 +02:00
this.timerStart,
this.duration,
2021-03-15 17:39:44 +02:00
required bool isLoading,
2021-02-16 20:48:15 +02:00
}) : super(
hetznerKey: dataState.hetznerKey,
cloudFlareKey: dataState.cloudFlareKey,
backblazeCredential: dataState.backblazeCredential,
serverDomain: dataState.serverDomain,
2021-02-16 20:48:15 +02:00
rootUser: dataState.rootUser,
serverDetails: dataState.serverDetails,
2021-02-16 20:48:15 +02:00
isServerStarted: dataState.isServerStarted,
2021-03-31 14:37:39 +03:00
isServerResetedFirstTime: dataState.isServerResetedFirstTime,
isServerResetedSecondTime: dataState.isServerResetedSecondTime,
2021-02-16 20:48:15 +02:00
isLoading: isLoading,
2022-02-08 08:59:19 +02:00
dnsMatches: dataState.dnsMatches,
2021-02-16 20:48:15 +02:00
);
2021-02-15 20:58:29 +02:00
final ServerInstallationNotFinished dataState;
2021-03-15 17:39:44 +02:00
final DateTime? timerStart;
final Duration? duration;
2021-02-15 20:58:29 +02:00
@override
2021-03-15 17:39:44 +02:00
List<Object?> get props => [
2021-02-15 20:58:29 +02:00
dataState,
timerStart,
duration,
];
}
enum ServerSetupProgress {
nothingYet,
hetznerFilled,
cloudFlareFilled,
backblazeFilled,
domainFilled,
userFilled,
serverCreated,
serverStarted,
serverResetedFirstTime,
serverResetedSecondTime,
}
class ServerInstallationNotFinished extends ServerInstallationState {
final bool isLoading;
2022-02-08 08:59:19 +02:00
final Map<String, bool>? dnsMatches;
ServerInstallationNotFinished({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
required this.isLoading,
2022-02-08 08:59:19 +02:00
required this.dnsMatches,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
serverDomain: serverDomain,
rootUser: rootUser,
serverDetails: serverDetails,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
serverDomain,
rootUser,
serverDetails,
isServerStarted,
isServerResetedFirstTime,
2022-02-08 08:59:19 +02:00
isLoading,
dnsMatches,
];
ServerInstallationNotFinished copyWith({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
bool? isServerStarted,
bool? isServerResetedFirstTime,
bool? isServerResetedSecondTime,
bool? isLoading,
2022-02-08 08:59:19 +02:00
Map<String, bool>? dnsMatches,
}) =>
ServerInstallationNotFinished(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
serverDomain: serverDomain ?? this.serverDomain,
rootUser: rootUser ?? this.rootUser,
serverDetails: serverDetails ?? this.serverDetails,
isServerStarted: isServerStarted ?? this.isServerStarted,
isServerResetedFirstTime:
isServerResetedFirstTime ?? this.isServerResetedFirstTime,
isServerResetedSecondTime:
isServerResetedSecondTime ?? this.isServerResetedSecondTime,
isLoading: isLoading ?? this.isLoading,
2022-02-08 08:59:19 +02:00
dnsMatches: dnsMatches ?? this.dnsMatches,
);
ServerInstallationFinished finish() => ServerInstallationFinished(
hetznerKey: hetznerKey!,
cloudFlareKey: cloudFlareKey!,
backblazeCredential: backblazeCredential!,
serverDomain: serverDomain!,
rootUser: rootUser!,
serverDetails: serverDetails!,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
}
class ServerInstallationEmpty extends ServerInstallationNotFinished {
ServerInstallationEmpty()
: super(
hetznerKey: null,
cloudFlareKey: null,
backblazeCredential: null,
serverDomain: null,
rootUser: null,
serverDetails: null,
isServerStarted: false,
isServerResetedFirstTime: false,
isServerResetedSecondTime: false,
isLoading: false,
2022-02-08 08:59:19 +02:00
dnsMatches: null,
);
}
class ServerInstallationFinished extends ServerInstallationState {
const ServerInstallationFinished({
required String hetznerKey,
required String cloudFlareKey,
required BackblazeCredential backblazeCredential,
required ServerDomain serverDomain,
required User rootUser,
required ServerHostingDetails serverDetails,
required bool isServerStarted,
required bool isServerResetedFirstTime,
required bool isServerResetedSecondTime,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
serverDomain: serverDomain,
rootUser: rootUser,
serverDetails: serverDetails,
isServerStarted: isServerStarted,
isServerResetedFirstTime: isServerResetedFirstTime,
isServerResetedSecondTime: isServerResetedSecondTime,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
serverDomain,
rootUser,
serverDetails,
isServerStarted,
isServerResetedFirstTime,
];
}
enum RecoveryStep {
Selecting,
RecoveryKey,
NewDeviceKey,
OldToken,
HetznerToken,
ServerSelection,
CloudflareToken,
BackblazeToken,
}
enum ServerRecoveryCapabilities {
none,
legacy,
loginTokens,
}
enum ServerRecoveryMethods {
newDeviceKey,
recoveryKey,
oldToken,
}
class ServerInstallationRecovery extends ServerInstallationState {
final RecoveryStep currentStep;
final ServerRecoveryCapabilities recoveryCapabilities;
const ServerInstallationRecovery({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
required RecoveryStep this.currentStep,
required ServerRecoveryCapabilities this.recoveryCapabilities,
}) : super(
hetznerKey: hetznerKey,
cloudFlareKey: cloudFlareKey,
backblazeCredential: backblazeCredential,
serverDomain: serverDomain,
rootUser: rootUser,
serverDetails: serverDetails,
isServerStarted: true,
isServerResetedFirstTime: true,
isServerResetedSecondTime: true,
);
@override
List<Object?> get props => [
hetznerKey,
cloudFlareKey,
backblazeCredential,
serverDomain,
rootUser,
serverDetails,
isServerStarted,
isServerResetedFirstTime,
currentStep
];
ServerInstallationRecovery copyWith({
String? hetznerKey,
String? cloudFlareKey,
BackblazeCredential? backblazeCredential,
ServerDomain? serverDomain,
User? rootUser,
ServerHostingDetails? serverDetails,
RecoveryStep? currentStep,
ServerRecoveryCapabilities? recoveryCapabilities,
}) =>
ServerInstallationRecovery(
hetznerKey: hetznerKey ?? this.hetznerKey,
cloudFlareKey: cloudFlareKey ?? this.cloudFlareKey,
backblazeCredential: backblazeCredential ?? this.backblazeCredential,
serverDomain: serverDomain ?? this.serverDomain,
rootUser: rootUser ?? this.rootUser,
serverDetails: serverDetails ?? this.serverDetails,
currentStep: currentStep ?? this.currentStep,
recoveryCapabilities: recoveryCapabilities ?? this.recoveryCapabilities,
);
2022-05-23 17:21:34 +03:00
ServerInstallationFinished finish() {
return ServerInstallationFinished(
hetznerKey: hetznerKey!,
cloudFlareKey: cloudFlareKey!,
backblazeCredential: backblazeCredential!,
serverDomain: serverDomain!,
rootUser: rootUser!,
serverDetails: serverDetails!,
isServerStarted: true,
isServerResetedFirstTime: true,
isServerResetedSecondTime: true,
);
}
}