diff --git a/lib/logic/cubit/backups/backups_cubit.dart b/lib/logic/cubit/backups/backups_cubit.dart index ca7e0a50..e6381542 100644 --- a/lib/logic/cubit/backups/backups_cubit.dart +++ b/lib/logic/cubit/backups/backups_cubit.dart @@ -29,6 +29,8 @@ class BackupsCubit extends ServerInstallationDependendCubit { final BackblazeBucket? bucket = getIt().backblazeBucket; final BackupConfiguration? backupConfig = await api.getBackupsConfiguration(); + final BackupsCredential? backupsCredential = + getIt().backblazeCredential; final List backups = await api.getBackups(); backups.sort((final a, final b) => b.time.compareTo(a.time)); emit( @@ -37,6 +39,7 @@ class BackupsCubit extends ServerInstallationDependendCubit { isInitialized: backupConfig?.isInitialized, autobackupPeriod: backupConfig?.autobackupPeriod ?? Duration.zero, autobackupQuotas: backupConfig?.autobackupQuotas, + backupsCredential: backupsCredential, backups: backups, preventActions: false, refreshing: false, @@ -45,6 +48,19 @@ class BackupsCubit extends ServerInstallationDependendCubit { } } + Future setBackupsKey( + final String keyId, + final String applicationKey, + ) async { + final BackupsCredential backupsCredential = BackupsCredential( + keyId: keyId, + applicationKey: applicationKey, + provider: BackupsProviderType.backblaze, + ); + await getIt().storeBackblazeCredential(backupsCredential); + emit(state.copyWith(backupsCredential: backupsCredential)); + } + Future initializeBackups() async { emit(state.copyWith(preventActions: true)); final String? encryptionKey = diff --git a/lib/logic/cubit/backups/backups_state.dart b/lib/logic/cubit/backups/backups_state.dart index 887396d7..b9d563eb 100644 --- a/lib/logic/cubit/backups/backups_state.dart +++ b/lib/logic/cubit/backups/backups_state.dart @@ -10,6 +10,7 @@ class BackupsState extends ServerInstallationDependendState { this.autobackupPeriod, this.backblazeBucket, this.autobackupQuotas, + this.backupsCredential, }); final bool isInitialized; @@ -20,6 +21,7 @@ class BackupsState extends ServerInstallationDependendState { final Duration? autobackupPeriod; final BackblazeBucket? backblazeBucket; final AutobackupQuotas? autobackupQuotas; + final BackupsCredential? backupsCredential; List serviceBackups(final String serviceId) => backups .where((final backup) => backup.serviceId == serviceId) @@ -43,6 +45,7 @@ class BackupsState extends ServerInstallationDependendState { final Duration? autobackupPeriod, final BackblazeBucket? backblazeBucket, final AutobackupQuotas? autobackupQuotas, + final BackupsCredential? backupsCredential, }) => BackupsState( isInitialized: isInitialized ?? this.isInitialized, @@ -50,12 +53,13 @@ class BackupsState extends ServerInstallationDependendState { preventActions: preventActions ?? this.preventActions, refreshTimer: refreshTimer ?? this.refreshTimer, refreshing: refreshing ?? this.refreshing, + backupsCredential: backupsCredential ?? this.backupsCredential, + backblazeBucket: backblazeBucket ?? this.backblazeBucket, + autobackupQuotas: autobackupQuotas ?? this.autobackupQuotas, // The autobackupPeriod might be null, so if the duration is set to 0, we // set it to null. autobackupPeriod: autobackupPeriod?.inSeconds == 0 ? null : autobackupPeriod ?? this.autobackupPeriod, - backblazeBucket: backblazeBucket ?? this.backblazeBucket, - autobackupQuotas: autobackupQuotas ?? this.autobackupQuotas, ); } diff --git a/lib/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart b/lib/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart index 3907b7e1..534c9c79 100644 --- a/lib/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart +++ b/lib/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart @@ -2,12 +2,12 @@ import 'dart:async'; import 'package:cubit_form/cubit_form.dart'; import 'package:selfprivacy/config/get_it_config.dart'; import 'package:selfprivacy/logic/api_maps/rest_maps/backblaze.dart'; -import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; +import 'package:selfprivacy/logic/cubit/backups/backups_cubit.dart'; import 'package:selfprivacy/logic/models/hive/backups_credential.dart'; import 'package:easy_localization/easy_localization.dart'; class BackblazeFormCubit extends FormCubit { - BackblazeFormCubit(this.serverInstallationCubit) { + BackblazeFormCubit(this.backupsCubit) { keyId = FieldCubit( initalValue: '', validations: [ @@ -27,13 +27,13 @@ class BackblazeFormCubit extends FormCubit { @override FutureOr onSubmit() async { - serverInstallationCubit.setBackblazeKey( + await backupsCubit.setBackupsKey( keyId.state.value, applicationKey.state.value, ); } - final ServerInstallationCubit serverInstallationCubit; + final BackupsCubit backupsCubit; late final FieldCubit keyId; late final FieldCubit applicationKey; diff --git a/lib/logic/cubit/server_installation/server_installation_cubit.dart b/lib/logic/cubit/server_installation/server_installation_cubit.dart index 612ec715..44bad44e 100644 --- a/lib/logic/cubit/server_installation/server_installation_cubit.dart +++ b/lib/logic/cubit/server_installation/server_installation_cubit.dart @@ -5,11 +5,8 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:equatable/equatable.dart'; import 'package:selfprivacy/config/get_it_config.dart'; import 'package:selfprivacy/logic/api_maps/graphql_maps/server_api/server_api.dart'; -import 'package:selfprivacy/logic/api_maps/rest_maps/backblaze.dart'; import 'package:selfprivacy/logic/api_maps/tls_options.dart'; import 'package:selfprivacy/logic/models/disk_size.dart'; -import 'package:selfprivacy/logic/models/hive/backblaze_bucket.dart'; -import 'package:selfprivacy/logic/models/hive/backups_credential.dart'; import 'package:selfprivacy/logic/models/callback_dialogue_branching.dart'; import 'package:selfprivacy/logic/models/hive/server_details.dart'; import 'package:selfprivacy/logic/models/hive/user.dart'; @@ -214,33 +211,6 @@ class ServerInstallationCubit extends Cubit { ); } - void setBackblazeKey(final String keyId, final String applicationKey) async { - final BackupsCredential backblazeCredential = BackupsCredential( - keyId: keyId, - applicationKey: applicationKey, - provider: BackupsProviderType.backblaze, - ); - final BackblazeBucket? bucket; - await repository.saveBackblazeKey(backblazeCredential); - if (state is ServerInstallationRecovery) { - final configuration = await ServerApi( - customToken: - (state as ServerInstallationRecovery).serverDetails!.apiToken, - isWithToken: true, - ).getBackupsConfiguration(); - if (configuration != null) { - try { - bucket = await BackblazeApi() - .fetchBucket(backblazeCredential, configuration); - await getIt().storeBackblazeBucket(bucket!); - } catch (e) { - print(e); - } - } - return; - } - } - void setDomain(final ServerDomain serverDomain) async { await repository.saveDomain(serverDomain); emit( diff --git a/lib/ui/pages/backups/backup_details.dart b/lib/ui/pages/backups/backup_details.dart index 574d26e5..b10615bf 100644 --- a/lib/ui/pages/backups/backup_details.dart +++ b/lib/ui/pages/backups/backup_details.dart @@ -75,7 +75,7 @@ class BackupDetailsPage extends StatelessWidget { BrandButton.rised( onPressed: preventActions ? null - : () => context.pushRoute(const BackupProviderPicker()), + : () => context.pushRoute(const BackupProviderPickerRoute()), text: 'backup.initialize'.tr(), ), ], diff --git a/lib/ui/pages/backups/backup_provider_picker.dart b/lib/ui/pages/backups/backup_provider_picker_page.dart similarity index 96% rename from lib/ui/pages/backups/backup_provider_picker.dart rename to lib/ui/pages/backups/backup_provider_picker_page.dart index bb41fa4a..c964e3e3 100644 --- a/lib/ui/pages/backups/backup_provider_picker.dart +++ b/lib/ui/pages/backups/backup_provider_picker_page.dart @@ -8,8 +8,8 @@ import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; import 'package:selfprivacy/ui/layouts/responsive_layout_with_infobox.dart'; @RoutePage() -class BackupProviderPicker extends StatelessWidget { - const BackupProviderPicker({ +class BackupProviderPickerPage extends StatelessWidget { + const BackupProviderPickerPage({ super.key, }); diff --git a/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart b/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart deleted file mode 100644 index 4b27e3ad..00000000 --- a/lib/ui/pages/setup/recovering/recovery_confirm_backblaze.dart +++ /dev/null @@ -1,79 +0,0 @@ -import 'package:cubit_form/cubit_form.dart'; -import 'package:easy_localization/easy_localization.dart'; -import 'package:flutter/material.dart'; -import 'package:selfprivacy/logic/cubit/forms/setup/initializing/backblaze_form_cubit.dart'; -import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; -import 'package:selfprivacy/logic/cubit/support_system/support_system_cubit.dart'; -import 'package:selfprivacy/ui/components/buttons/brand_button.dart'; -import 'package:selfprivacy/ui/layouts/brand_hero_screen.dart'; - -class RecoveryConfirmBackblaze extends StatelessWidget { - const RecoveryConfirmBackblaze({super.key}); - - @override - Widget build(final BuildContext context) { - final ServerInstallationCubit appConfig = - context.watch(); - - return BlocProvider( - create: (final BuildContext context) => BackblazeFormCubit(appConfig), - child: Builder( - builder: (final BuildContext context) { - final FormCubitState formCubitState = - context.watch().state; - - return BrandHeroScreen( - heroTitle: 'recovering.provider_connected'.tr(args: ['Backblaze']), - heroSubtitle: 'recovering.provider_connected_description'.tr( - args: ['Backblaze'], - ), - hasBackButton: true, - ignoreBreakpoints: true, - hasSupportDrawer: true, - onBackButtonPressed: () { - Navigator.of(context).popUntil((final route) => route.isFirst); - }, - hasFlashButton: false, - children: [ - CubitFormTextField( - autofocus: true, - formFieldCubit: context.read().keyId, - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: 'KeyID', - ), - ), - const SizedBox(height: 16), - CubitFormTextField( - formFieldCubit: - context.read().applicationKey, - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: 'Master Application Key', - ), - ), - const SizedBox(height: 16), - BrandButton.rised( - onPressed: formCubitState.isSubmitting - ? null - : () => context.read().trySubmit(), - text: 'basis.connect'.tr(), - ), - const SizedBox(height: 16), - Builder( - builder: (final context) => BrandButton.text( - onPressed: () => - context.read().showArticle( - article: 'how_backblaze', - context: context, - ), - title: 'initializing.how'.tr(), - ), - ), - ], - ); - }, - ), - ); - } -} diff --git a/lib/ui/router/router.dart b/lib/ui/router/router.dart index 1c01b4fc..1433e1c3 100644 --- a/lib/ui/router/router.dart +++ b/lib/ui/router/router.dart @@ -25,6 +25,7 @@ import 'package:selfprivacy/ui/pages/services/services.dart'; import 'package:selfprivacy/ui/pages/setup/initializing/initializing.dart'; import 'package:selfprivacy/ui/pages/setup/recovering/recovery_routing.dart'; import 'package:selfprivacy/ui/pages/users/users.dart'; +import 'package:selfprivacy/ui/pages/backups/backup_provider_picker_page.dart'; part 'router.gr.dart'; @@ -100,7 +101,7 @@ class RootRouter extends _$RootRouter { AutoRoute(page: BackupsListRoute.page), AutoRoute(page: ServerStorageRoute.page), AutoRoute(page: ExtendingVolumeRoute.page), - AutoRoute(page: BackupProviderPicker.page), + AutoRoute(page: BackupProviderPickerRoute.page), ], ), AutoRoute(page: ServicesMigrationRoute.page), diff --git a/lib/ui/router/router.gr.dart b/lib/ui/router/router.gr.dart index 7e880a0d..80802db2 100644 --- a/lib/ui/router/router.gr.dart +++ b/lib/ui/router/router.gr.dart @@ -186,10 +186,10 @@ abstract class _$RootRouter extends RootStackRouter { child: const RecoveryRouting(), ); }, - BackupProviderPicker.name: (routeData) { + BackupProviderPickerRoute.name: (routeData) { return AutoRoutePage( routeData: routeData, - child: const BackupProviderPicker(), + child: const BackupProviderPickerPage(), ); }, }; @@ -691,15 +691,15 @@ class RecoveryRoute extends PageRouteInfo { } /// generated route for -/// [BackupProviderPicker] -class BackupProviderPicker extends PageRouteInfo { - const BackupProviderPicker({List? children}) +/// [BackupProviderPickerPage] +class BackupProviderPickerRoute extends PageRouteInfo { + const BackupProviderPickerRoute({List? children}) : super( - BackupProviderPicker.name, + BackupProviderPickerRoute.name, initialChildren: children, ); - static const String name = 'BackupProviderPicker'; + static const String name = 'BackupProviderPickerRoute'; static const PageInfo page = PageInfo(name); }