mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-11 18:39:45 +00:00
Refactor infrastructure
Co-authored-by: Inex Code <inex.code@selfprivacy.org>
This commit is contained in:
parent
4a42733d31
commit
129c1bb4c6
|
@ -3,21 +3,21 @@ import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_bucket.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
|
|
||||||
class HiveConfig {
|
class HiveConfig {
|
||||||
static Future<void> init() async {
|
static Future<void> init() async {
|
||||||
await Hive.initFlutter();
|
await Hive.initFlutter();
|
||||||
Hive.registerAdapter(UserAdapter());
|
Hive.registerAdapter(UserAdapter());
|
||||||
Hive.registerAdapter(HetznerServerDetailsAdapter());
|
Hive.registerAdapter(ServerHostingDetailsAdapter());
|
||||||
Hive.registerAdapter(ServerDomainAdapter());
|
Hive.registerAdapter(ServerDomainAdapter());
|
||||||
Hive.registerAdapter(BackblazeCredentialAdapter());
|
Hive.registerAdapter(BackblazeCredentialAdapter());
|
||||||
Hive.registerAdapter(BackblazeBucketAdapter());
|
Hive.registerAdapter(BackblazeBucketAdapter());
|
||||||
Hive.registerAdapter(HetznerDataBaseAdapter());
|
Hive.registerAdapter(ServerVolumeAdapter());
|
||||||
|
|
||||||
await Hive.openBox(BNames.appSettings);
|
await Hive.openBox(BNames.appSettings);
|
||||||
await Hive.openBox<User>(BNames.users);
|
await Hive.openBox<User>(BNames.users);
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
|
|
||||||
class BackblazeApiAuth {
|
class BackblazeApiAuth {
|
||||||
BackblazeApiAuth({required this.authorizationToken, required this.apiUrl});
|
BackblazeApiAuth({required this.authorizationToken, required this.apiUrl});
|
||||||
|
|
|
@ -3,8 +3,8 @@ import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/dns_records.dart';
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||||
|
|
||||||
class CloudflareApi extends ApiMap {
|
class CloudflareApi extends ApiMap {
|
||||||
CloudflareApi({this.hasLogger = false, this.isWithToken = true});
|
CloudflareApi({this.hasLogger = false, this.isWithToken = true});
|
||||||
|
|
|
@ -4,9 +4,9 @@ import 'dart:io';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
import 'package:selfprivacy/logic/api_maps/api_map.dart';
|
||||||
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:selfprivacy/utils/password_generator.dart';
|
import 'package:selfprivacy/utils/password_generator.dart';
|
||||||
|
|
||||||
class HetznerApi extends ApiMap {
|
class HetznerApi extends ApiMap {
|
||||||
|
@ -140,8 +140,9 @@ class HetznerApi extends ApiMap {
|
||||||
id: serverCreateResponse.data['server']['id'],
|
id: serverCreateResponse.data['server']['id'],
|
||||||
ip4: serverCreateResponse.data['server']['public_net']['ipv4']['ip'],
|
ip4: serverCreateResponse.data['server']['public_net']['ipv4']['ip'],
|
||||||
createTime: DateTime.now(),
|
createTime: DateTime.now(),
|
||||||
dataBase: dataBase,
|
volume: dataBase,
|
||||||
apiToken: apiToken,
|
apiToken: apiToken,
|
||||||
|
provider: ServerProvider.Hetzner,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,10 +4,10 @@ import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/get_it/ssh.dart';
|
import 'package:selfprivacy/logic/get_it/ssh.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
|
|
||||||
import 'app_config_repository.dart';
|
import 'app_config_repository.dart';
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
|
|
||||||
final repository = AppConfigRepository();
|
final repository = AppConfigRepository();
|
||||||
|
|
||||||
|
Timer? timer;
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
var state = await repository.load();
|
var state = await repository.load();
|
||||||
|
|
||||||
|
@ -45,17 +47,68 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void runDelayed(
|
void setHetznerKey(String hetznerKey) async {
|
||||||
void Function() work, Duration delay, AppConfigNotFinished? state) async {
|
await repository.saveHetznerKey(hetznerKey);
|
||||||
final dataState = state ?? this.state as AppConfigNotFinished;
|
emit((state as AppConfigNotFinished).copyWith(hetznerKey: hetznerKey));
|
||||||
|
}
|
||||||
|
|
||||||
emit(TimerState(
|
void setCloudflareKey(String cloudFlareKey) async {
|
||||||
dataState: dataState,
|
await repository.saveCloudFlareKey(cloudFlareKey);
|
||||||
timerStart: DateTime.now(),
|
emit(
|
||||||
duration: delay,
|
(state as AppConfigNotFinished).copyWith(cloudFlareKey: cloudFlareKey));
|
||||||
isLoading: false,
|
}
|
||||||
));
|
|
||||||
timer = Timer(delay, work);
|
void setBackblazeKey(String keyId, String applicationKey) async {
|
||||||
|
var backblazeCredential = BackblazeCredential(
|
||||||
|
keyId: keyId,
|
||||||
|
applicationKey: applicationKey,
|
||||||
|
);
|
||||||
|
await repository.saveBackblazeKey(backblazeCredential);
|
||||||
|
emit((state as AppConfigNotFinished)
|
||||||
|
.copyWith(backblazeCredential: backblazeCredential));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDomain(ServerDomain serverDomain) async {
|
||||||
|
await repository.saveDomain(serverDomain);
|
||||||
|
emit((state as AppConfigNotFinished).copyWith(serverDomain: serverDomain));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setRootUser(User rootUser) async {
|
||||||
|
await repository.saveRootUser(rootUser);
|
||||||
|
emit((state as AppConfigNotFinished).copyWith(rootUser: rootUser));
|
||||||
|
}
|
||||||
|
|
||||||
|
void createServerAndSetDnsRecords() async {
|
||||||
|
AppConfigNotFinished _stateCopy = state as AppConfigNotFinished;
|
||||||
|
var onSuccess = (ServerHostingDetails serverDetails) async {
|
||||||
|
await repository.createDnsRecords(
|
||||||
|
serverDetails.ip4,
|
||||||
|
state.serverDomain!,
|
||||||
|
);
|
||||||
|
|
||||||
|
emit((state as AppConfigNotFinished).copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
serverDetails: serverDetails,
|
||||||
|
));
|
||||||
|
runDelayed(startServerIfDnsIsOkay, Duration(seconds: 30), null);
|
||||||
|
};
|
||||||
|
|
||||||
|
var onCancel =
|
||||||
|
() => emit((state as AppConfigNotFinished).copyWith(isLoading: false));
|
||||||
|
|
||||||
|
try {
|
||||||
|
emit((state as AppConfigNotFinished).copyWith(isLoading: true));
|
||||||
|
await repository.createServer(
|
||||||
|
state.rootUser!,
|
||||||
|
state.serverDomain!.domainName,
|
||||||
|
state.cloudFlareKey!,
|
||||||
|
state.backblazeCredential!,
|
||||||
|
onCancel: onCancel,
|
||||||
|
onSuccess: onSuccess,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(_stateCopy);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startServerIfDnsIsOkay({AppConfigNotFinished? state}) async {
|
void startServerIfDnsIsOkay({AppConfigNotFinished? state}) async {
|
||||||
|
@ -165,8 +218,6 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer? timer;
|
|
||||||
|
|
||||||
void finishCheckIfServerIsOkay({
|
void finishCheckIfServerIsOkay({
|
||||||
AppConfigNotFinished? state,
|
AppConfigNotFinished? state,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -186,6 +237,19 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void runDelayed(
|
||||||
|
void Function() work, Duration delay, AppConfigNotFinished? state) async {
|
||||||
|
final dataState = state ?? this.state as AppConfigNotFinished;
|
||||||
|
|
||||||
|
emit(TimerState(
|
||||||
|
dataState: dataState,
|
||||||
|
timerStart: DateTime.now(),
|
||||||
|
duration: delay,
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
timer = Timer(delay, work);
|
||||||
|
}
|
||||||
|
|
||||||
void clearAppConfig() {
|
void clearAppConfig() {
|
||||||
closeTimer();
|
closeTimer();
|
||||||
|
|
||||||
|
@ -216,70 +280,6 @@ class AppConfigCubit extends Cubit<AppConfigState> {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setHetznerKey(String hetznerKey) async {
|
|
||||||
await repository.saveHetznerKey(hetznerKey);
|
|
||||||
emit((state as AppConfigNotFinished).copyWith(hetznerKey: hetznerKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCloudflareKey(String cloudFlareKey) async {
|
|
||||||
await repository.saveCloudFlareKey(cloudFlareKey);
|
|
||||||
emit(
|
|
||||||
(state as AppConfigNotFinished).copyWith(cloudFlareKey: cloudFlareKey));
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBackblazeKey(String keyId, String applicationKey) async {
|
|
||||||
var backblazeCredential = BackblazeCredential(
|
|
||||||
keyId: keyId,
|
|
||||||
applicationKey: applicationKey,
|
|
||||||
);
|
|
||||||
await repository.saveBackblazeKey(backblazeCredential);
|
|
||||||
emit((state as AppConfigNotFinished)
|
|
||||||
.copyWith(backblazeCredential: backblazeCredential));
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDomain(ServerDomain serverDomain) async {
|
|
||||||
await repository.saveDomain(serverDomain);
|
|
||||||
emit((state as AppConfigNotFinished).copyWith(serverDomain: serverDomain));
|
|
||||||
}
|
|
||||||
|
|
||||||
void setRootUser(User rootUser) async {
|
|
||||||
await repository.saveRootUser(rootUser);
|
|
||||||
emit((state as AppConfigNotFinished).copyWith(rootUser: rootUser));
|
|
||||||
}
|
|
||||||
|
|
||||||
void createServerAndSetDnsRecords() async {
|
|
||||||
AppConfigNotFinished _stateCopy = state as AppConfigNotFinished;
|
|
||||||
var onSuccess = (ServerHostingDetails serverDetails) async {
|
|
||||||
await repository.createDnsRecords(
|
|
||||||
serverDetails.ip4,
|
|
||||||
state.serverDomain!,
|
|
||||||
);
|
|
||||||
|
|
||||||
emit((state as AppConfigNotFinished).copyWith(
|
|
||||||
isLoading: false,
|
|
||||||
serverDetails: serverDetails,
|
|
||||||
));
|
|
||||||
runDelayed(startServerIfDnsIsOkay, Duration(seconds: 30), null);
|
|
||||||
};
|
|
||||||
|
|
||||||
var onCancel =
|
|
||||||
() => emit((state as AppConfigNotFinished).copyWith(isLoading: false));
|
|
||||||
|
|
||||||
try {
|
|
||||||
emit((state as AppConfigNotFinished).copyWith(isLoading: true));
|
|
||||||
await repository.createServer(
|
|
||||||
state.rootUser!,
|
|
||||||
state.serverDomain!.domainName,
|
|
||||||
state.cloudFlareKey!,
|
|
||||||
state.backblazeCredential!,
|
|
||||||
onCancel: onCancel,
|
|
||||||
onSuccess: onSuccess,
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
emit(_stateCopy);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
closeTimer();
|
closeTimer();
|
||||||
return super.close();
|
return super.close();
|
||||||
|
|
|
@ -7,11 +7,11 @@ import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/message.dart';
|
import 'package:selfprivacy/logic/models/message.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ class AppConfigRepository {
|
||||||
backblazeCredential: backblazeCredential,
|
backblazeCredential: backblazeCredential,
|
||||||
serverDetails: serverDetails,
|
serverDetails: serverDetails,
|
||||||
rootUser: box.get(BNames.rootUser),
|
rootUser: box.get(BNames.rootUser),
|
||||||
currentStep: getCurrentRecoveryStep(
|
currentStep: _getCurrentRecoveryStep(
|
||||||
hetznerToken, cloudflareToken, serverDomain!, serverDetails),
|
hetznerToken, cloudflareToken, serverDomain!, serverDetails),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class AppConfigRepository {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
RecoveryStep getCurrentRecoveryStep(
|
RecoveryStep _getCurrentRecoveryStep(
|
||||||
String? hetznerToken,
|
String? hetznerToken,
|
||||||
String? cloudflareToken,
|
String? cloudflareToken,
|
||||||
ServerDomain serverDomain,
|
ServerDomain serverDomain,
|
||||||
|
|
|
@ -5,8 +5,8 @@ import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/backblaze.dart';
|
import 'package:selfprivacy/logic/api_maps/backblaze.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_bucket.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||||
import 'package:selfprivacy/logic/models/backup.dart';
|
import 'package:selfprivacy/logic/models/json/backup.dart';
|
||||||
|
|
||||||
part 'backups_state.dart';
|
part 'backups_state.dart';
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/dns_records.dart';
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
||||||
|
|
||||||
import '../../api_maps/cloudflare.dart';
|
import '../../api_maps/cloudflare.dart';
|
||||||
import '../../api_maps/server.dart';
|
import '../../api_maps/server.dart';
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'dart:async';
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/backblaze.dart';
|
import 'package:selfprivacy/logic/api_maps/backblaze.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
class BackblazeFormCubit extends FormCubit {
|
class BackblazeFormCubit extends FormCubit {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
import 'package:selfprivacy/logic/api_maps/cloudflare.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
|
|
||||||
class DomainSetupCubit extends Cubit<DomainSetupState> {
|
class DomainSetupCubit extends Cubit<DomainSetupState> {
|
||||||
DomainSetupCubit(this.initializingCubit) : super(Initial());
|
DomainSetupCubit(this.initializingCubit) : super(Initial());
|
||||||
|
|
|
@ -3,7 +3,7 @@ import 'dart:async';
|
||||||
import 'package:cubit_form/cubit_form.dart';
|
import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
|
|
||||||
class RootUserFormCubit extends FormCubit {
|
class RootUserFormCubit extends FormCubit {
|
||||||
RootUserFormCubit(
|
RootUserFormCubit(
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
|
|
||||||
class RecoveryDomainFormCubit extends FormCubit {
|
class RecoveryDomainFormCubit extends FormCubit {
|
||||||
RecoveryDomainFormCubit(
|
RecoveryDomainFormCubit(
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
|
|
||||||
class SshFormCubit extends FormCubit {
|
class SshFormCubit extends FormCubit {
|
||||||
SshFormCubit({
|
SshFormCubit({
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:cubit_form/cubit_form.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
import 'package:selfprivacy/logic/cubit/forms/factories/field_cubit_factory.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:selfprivacy/utils/password_generator.dart';
|
import 'package:selfprivacy/utils/password_generator.dart';
|
||||||
|
|
||||||
class UserFormCubit extends FormCubit {
|
class UserFormCubit extends FormCubit {
|
||||||
|
|
|
@ -2,8 +2,8 @@ import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_repository.dart';
|
import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_info_repository.dart';
|
||||||
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
import 'package:selfprivacy/logic/models/json/auto_upgrade_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
|
|
||||||
part 'server_detailed_info_state.dart';
|
part 'server_detailed_info_state.dart';
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
import 'package:selfprivacy/logic/api_maps/hetzner.dart';
|
||||||
import 'package:selfprivacy/logic/api_maps/server.dart';
|
import 'package:selfprivacy/logic/api_maps/server.dart';
|
||||||
import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart';
|
import 'package:selfprivacy/logic/models/json/auto_upgrade_settings.dart';
|
||||||
import 'package:selfprivacy/logic/models/hetzner_server_info.dart';
|
import 'package:selfprivacy/logic/models/json/hetzner_server_info.dart';
|
||||||
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
import 'package:selfprivacy/logic/models/timezone_settings.dart';
|
||||||
|
|
||||||
class ServerDetailsRepository {
|
class ServerDetailsRepository {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import 'package:bloc/bloc.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:selfprivacy/config/hive_config.dart';
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config_dependent/authentication_dependend_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
|
|
||||||
import '../../api_maps/server.dart';
|
import '../../api_maps/server.dart';
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:selfprivacy/config/hive_config.dart';
|
import 'package:selfprivacy/config/hive_config.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_bucket.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart';
|
||||||
import 'package:selfprivacy/logic/models/backblaze_credential.dart';
|
import 'package:selfprivacy/logic/models/hive/backblaze_credential.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_domain.dart';
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
||||||
import 'package:selfprivacy/logic/models/server_details.dart';
|
import 'package:selfprivacy/logic/models/hive/server_details.dart';
|
||||||
|
|
||||||
class ApiConfigModel {
|
class ApiConfigModel {
|
||||||
Box _box = Hive.box(BNames.appConfig);
|
Box _box = Hive.box(BNames.appConfig);
|
||||||
|
|
13
lib/logic/models/hive/README.md
Normal file
13
lib/logic/models/hive/README.md
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Registered Hive Types
|
||||||
|
|
||||||
|
1. User
|
||||||
|
2. ServerHostingDetails
|
||||||
|
3. ServerDomain
|
||||||
|
4. BackblazeCredential
|
||||||
|
5. ServerVolume
|
||||||
|
6. BackblazeBucket
|
||||||
|
|
||||||
|
|
||||||
|
## Enums
|
||||||
|
100. DnsProvider
|
||||||
|
101. ServerProvider
|
|
@ -8,8 +8,9 @@ class ServerHostingDetails {
|
||||||
required this.ip4,
|
required this.ip4,
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.createTime,
|
required this.createTime,
|
||||||
required this.dataBase,
|
required this.volume,
|
||||||
required this.apiToken,
|
required this.apiToken,
|
||||||
|
required this.provider,
|
||||||
this.startTime,
|
this.startTime,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -26,19 +27,23 @@ class ServerHostingDetails {
|
||||||
final DateTime? startTime;
|
final DateTime? startTime;
|
||||||
|
|
||||||
@HiveField(4)
|
@HiveField(4)
|
||||||
final ServerVolume dataBase;
|
final ServerVolume volume;
|
||||||
|
|
||||||
@HiveField(5)
|
@HiveField(5)
|
||||||
final String apiToken;
|
final String apiToken;
|
||||||
|
|
||||||
|
@HiveField(6, defaultValue: ServerProvider.Hetzner)
|
||||||
|
final ServerProvider provider;
|
||||||
|
|
||||||
ServerHostingDetails copyWith({DateTime? startTime}) {
|
ServerHostingDetails copyWith({DateTime? startTime}) {
|
||||||
return ServerHostingDetails(
|
return ServerHostingDetails(
|
||||||
startTime: startTime ?? this.startTime,
|
startTime: startTime ?? this.startTime,
|
||||||
createTime: createTime,
|
createTime: createTime,
|
||||||
id: id,
|
id: id,
|
||||||
ip4: ip4,
|
ip4: ip4,
|
||||||
dataBase: dataBase,
|
volume: volume,
|
||||||
apiToken: apiToken,
|
apiToken: apiToken,
|
||||||
|
provider: provider,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,3 +62,11 @@ class ServerVolume {
|
||||||
@HiveField(2)
|
@HiveField(2)
|
||||||
String name;
|
String name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HiveType(typeId: 101)
|
||||||
|
enum ServerProvider {
|
||||||
|
@HiveField(0)
|
||||||
|
Unknown,
|
||||||
|
@HiveField(1)
|
||||||
|
Hetzner,
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ part of 'server_details.dart';
|
||||||
// TypeAdapterGenerator
|
// TypeAdapterGenerator
|
||||||
// **************************************************************************
|
// **************************************************************************
|
||||||
|
|
||||||
class HetznerServerDetailsAdapter extends TypeAdapter<ServerHostingDetails> {
|
class ServerHostingDetailsAdapter extends TypeAdapter<ServerHostingDetails> {
|
||||||
@override
|
@override
|
||||||
final int typeId = 2;
|
final int typeId = 2;
|
||||||
|
|
||||||
|
@ -20,8 +20,11 @@ class HetznerServerDetailsAdapter extends TypeAdapter<ServerHostingDetails> {
|
||||||
ip4: fields[0] as String,
|
ip4: fields[0] as String,
|
||||||
id: fields[1] as int,
|
id: fields[1] as int,
|
||||||
createTime: fields[3] as DateTime?,
|
createTime: fields[3] as DateTime?,
|
||||||
dataBase: fields[4] as ServerVolume,
|
volume: fields[4] as ServerVolume,
|
||||||
apiToken: fields[5] as String,
|
apiToken: fields[5] as String,
|
||||||
|
provider: fields[6] == null
|
||||||
|
? ServerProvider.Hetzner
|
||||||
|
: fields[6] as ServerProvider,
|
||||||
startTime: fields[2] as DateTime?,
|
startTime: fields[2] as DateTime?,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +32,7 @@ class HetznerServerDetailsAdapter extends TypeAdapter<ServerHostingDetails> {
|
||||||
@override
|
@override
|
||||||
void write(BinaryWriter writer, ServerHostingDetails obj) {
|
void write(BinaryWriter writer, ServerHostingDetails obj) {
|
||||||
writer
|
writer
|
||||||
..writeByte(6)
|
..writeByte(7)
|
||||||
..writeByte(0)
|
..writeByte(0)
|
||||||
..write(obj.ip4)
|
..write(obj.ip4)
|
||||||
..writeByte(1)
|
..writeByte(1)
|
||||||
|
@ -39,9 +42,11 @@ class HetznerServerDetailsAdapter extends TypeAdapter<ServerHostingDetails> {
|
||||||
..writeByte(2)
|
..writeByte(2)
|
||||||
..write(obj.startTime)
|
..write(obj.startTime)
|
||||||
..writeByte(4)
|
..writeByte(4)
|
||||||
..write(obj.dataBase)
|
..write(obj.volume)
|
||||||
..writeByte(5)
|
..writeByte(5)
|
||||||
..write(obj.apiToken);
|
..write(obj.apiToken)
|
||||||
|
..writeByte(6)
|
||||||
|
..write(obj.provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -50,12 +55,12 @@ class HetznerServerDetailsAdapter extends TypeAdapter<ServerHostingDetails> {
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
identical(this, other) ||
|
identical(this, other) ||
|
||||||
other is HetznerServerDetailsAdapter &&
|
other is ServerHostingDetailsAdapter &&
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
typeId == other.typeId;
|
typeId == other.typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HetznerDataBaseAdapter extends TypeAdapter<ServerVolume> {
|
class ServerVolumeAdapter extends TypeAdapter<ServerVolume> {
|
||||||
@override
|
@override
|
||||||
final int typeId = 5;
|
final int typeId = 5;
|
||||||
|
|
||||||
|
@ -87,7 +92,46 @@ class HetznerDataBaseAdapter extends TypeAdapter<ServerVolume> {
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
identical(this, other) ||
|
identical(this, other) ||
|
||||||
other is HetznerDataBaseAdapter &&
|
other is ServerVolumeAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ServerProviderAdapter extends TypeAdapter<ServerProvider> {
|
||||||
|
@override
|
||||||
|
final int typeId = 101;
|
||||||
|
|
||||||
|
@override
|
||||||
|
ServerProvider read(BinaryReader reader) {
|
||||||
|
switch (reader.readByte()) {
|
||||||
|
case 0:
|
||||||
|
return ServerProvider.Unknown;
|
||||||
|
case 1:
|
||||||
|
return ServerProvider.Hetzner;
|
||||||
|
default:
|
||||||
|
return ServerProvider.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, ServerProvider obj) {
|
||||||
|
switch (obj) {
|
||||||
|
case ServerProvider.Unknown:
|
||||||
|
writer.writeByte(0);
|
||||||
|
break;
|
||||||
|
case ServerProvider.Hetzner:
|
||||||
|
writer.writeByte(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is ServerProviderAdapter &&
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
typeId == other.typeId;
|
typeId == other.typeId;
|
||||||
}
|
}
|
|
@ -2,11 +2,6 @@ import 'package:hive/hive.dart';
|
||||||
|
|
||||||
part 'server_domain.g.dart';
|
part 'server_domain.g.dart';
|
||||||
|
|
||||||
enum DnsProvider {
|
|
||||||
Unknown,
|
|
||||||
Cloudflare,
|
|
||||||
}
|
|
||||||
|
|
||||||
@HiveType(typeId: 3)
|
@HiveType(typeId: 3)
|
||||||
class ServerDomain {
|
class ServerDomain {
|
||||||
ServerDomain({
|
ServerDomain({
|
||||||
|
@ -29,3 +24,11 @@ class ServerDomain {
|
||||||
return '$domainName: $zoneId';
|
return '$domainName: $zoneId';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HiveType(typeId: 100)
|
||||||
|
enum DnsProvider {
|
||||||
|
@HiveField(0)
|
||||||
|
Unknown,
|
||||||
|
@HiveField(1)
|
||||||
|
Cloudflare,
|
||||||
|
}
|
|
@ -46,3 +46,42 @@ class ServerDomainAdapter extends TypeAdapter<ServerDomain> {
|
||||||
runtimeType == other.runtimeType &&
|
runtimeType == other.runtimeType &&
|
||||||
typeId == other.typeId;
|
typeId == other.typeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DnsProviderAdapter extends TypeAdapter<DnsProvider> {
|
||||||
|
@override
|
||||||
|
final int typeId = 100;
|
||||||
|
|
||||||
|
@override
|
||||||
|
DnsProvider read(BinaryReader reader) {
|
||||||
|
switch (reader.readByte()) {
|
||||||
|
case 0:
|
||||||
|
return DnsProvider.Unknown;
|
||||||
|
case 1:
|
||||||
|
return DnsProvider.Cloudflare;
|
||||||
|
default:
|
||||||
|
return DnsProvider.Unknown;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, DnsProvider obj) {
|
||||||
|
switch (obj) {
|
||||||
|
case DnsProvider.Unknown:
|
||||||
|
writer.writeByte(0);
|
||||||
|
break;
|
||||||
|
case DnsProvider.Cloudflare:
|
||||||
|
writer.writeByte(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is DnsProviderAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
import 'package:selfprivacy/logic/common_enum/common_enum.dart';
|
||||||
import 'package:selfprivacy/utils/password_generator.dart';
|
import 'package:selfprivacy/utils/password_generator.dart';
|
||||||
|
|
||||||
import 'user.dart';
|
import 'hive/user.dart';
|
||||||
|
|
||||||
@immutable
|
@immutable
|
||||||
class Job extends Equatable {
|
class Job extends Equatable {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import 'package:selfprivacy/config/brand_colors.dart';
|
||||||
import 'package:selfprivacy/config/get_it_config.dart';
|
import 'package:selfprivacy/config/get_it_config.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/backup.dart';
|
import 'package:selfprivacy/logic/models/json/backup.dart';
|
||||||
import 'package:selfprivacy/logic/models/state_types.dart';
|
import 'package:selfprivacy/logic/models/state_types.dart';
|
||||||
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
||||||
|
|
|
@ -35,7 +35,7 @@ class InitializingPage extends StatelessWidget {
|
||||||
() => _stepCheck(cubit),
|
() => _stepCheck(cubit),
|
||||||
() => _stepCheck(cubit),
|
() => _stepCheck(cubit),
|
||||||
() => Container(child: Center(child: Text('initializing.finish'.tr())))
|
() => Container(child: Center(child: Text('initializing.finish'.tr())))
|
||||||
][cubit.state.progress]();
|
][cubit.state.progress.index]();
|
||||||
return BlocListener<AppConfigCubit, AppConfigState>(
|
return BlocListener<AppConfigCubit, AppConfigState>(
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (cubit.state is AppConfigFinished) {
|
if (cubit.state is AppConfigFinished) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
|
||||||
import '../../../config/brand_colors.dart';
|
import '../../../config/brand_colors.dart';
|
||||||
import '../../../config/brand_theme.dart';
|
import '../../../config/brand_theme.dart';
|
||||||
import '../../../logic/cubit/jobs/jobs_cubit.dart';
|
import '../../../logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import '../../../logic/models/user.dart';
|
import '../../../logic/models/hive/user.dart';
|
||||||
import '../../components/brand_button/brand_button.dart';
|
import '../../components/brand_button/brand_button.dart';
|
||||||
import '../../components/brand_header/brand_header.dart';
|
import '../../components/brand_header/brand_header.dart';
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import 'package:selfprivacy/logic/cubit/forms/user/user_form_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/jobs/jobs_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
import 'package:selfprivacy/logic/cubit/users/users_cubit.dart';
|
||||||
import 'package:selfprivacy/logic/models/job.dart';
|
import 'package:selfprivacy/logic/models/job.dart';
|
||||||
import 'package:selfprivacy/logic/models/user.dart';
|
import 'package:selfprivacy/logic/models/hive/user.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
import 'package:selfprivacy/ui/components/brand_bottom_sheet/brand_bottom_sheet.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
import 'package:selfprivacy/ui/components/brand_button/brand_button.dart';
|
||||||
import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
|
import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
|
||||||
|
|
Loading…
Reference in a new issue