mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-06 16:14:15 +00:00
refactor: Getters for backup-related jobs
This commit is contained in:
parent
290c4166c5
commit
2b8d3ee6d0
|
@ -35,7 +35,7 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
backblazeBucket: bucket,
|
backblazeBucket: bucket,
|
||||||
isInitialized: backupConfig?.isInitialized,
|
isInitialized: backupConfig?.isInitialized,
|
||||||
autobackupPeriod: backupConfig?.autobackupPeriod,
|
autobackupPeriod: backupConfig?.autobackupPeriod ?? Duration.zero,
|
||||||
backups: backups,
|
backups: backups,
|
||||||
preventActions: false,
|
preventActions: false,
|
||||||
refreshing: false,
|
refreshing: false,
|
||||||
|
@ -164,8 +164,8 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
||||||
|
|
||||||
Future<void> forceUpdateBackups() async {
|
Future<void> forceUpdateBackups() async {
|
||||||
emit(state.copyWith(preventActions: true));
|
emit(state.copyWith(preventActions: true));
|
||||||
await api.forceBackupListReload();
|
|
||||||
getIt<NavigationService>().showSnackBar('backup.refetching_list'.tr());
|
getIt<NavigationService>().showSnackBar('backup.refetching_list'.tr());
|
||||||
|
await api.forceBackupListReload();
|
||||||
emit(state.copyWith(preventActions: false));
|
emit(state.copyWith(preventActions: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,12 +187,30 @@ class BackupsCubit extends ServerInstallationDependendCubit<BackupsState> {
|
||||||
|
|
||||||
Future<void> restoreBackup(final String backupId) async {
|
Future<void> restoreBackup(final String backupId) async {
|
||||||
emit(state.copyWith(preventActions: true));
|
emit(state.copyWith(preventActions: true));
|
||||||
|
await api.restoreBackup(backupId);
|
||||||
/// TOOD: ???
|
|
||||||
//await api.restoreBackup(backupId);
|
|
||||||
emit(state.copyWith(preventActions: false));
|
emit(state.copyWith(preventActions: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> setAutobackupPeriod(final Duration? period) async {
|
||||||
|
emit(state.copyWith(preventActions: true));
|
||||||
|
final result = await api.setAutobackupPeriod(period: period?.inMinutes);
|
||||||
|
if (result.success == false) {
|
||||||
|
getIt<NavigationService>()
|
||||||
|
.showSnackBar(result.message ?? 'Unknown error');
|
||||||
|
emit(state.copyWith(preventActions: false));
|
||||||
|
} else {
|
||||||
|
getIt<NavigationService>()
|
||||||
|
.showSnackBar('backup.autobackup_period_set'.tr());
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
preventActions: false,
|
||||||
|
autobackupPeriod: period ?? Duration.zero,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await updateBackups();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void clear() async {
|
void clear() async {
|
||||||
emit(const BackupsState());
|
emit(const BackupsState());
|
||||||
|
|
|
@ -19,6 +19,10 @@ class BackupsState extends ServerInstallationDependendState {
|
||||||
final Duration? autobackupPeriod;
|
final Duration? autobackupPeriod;
|
||||||
final BackblazeBucket? backblazeBucket;
|
final BackblazeBucket? backblazeBucket;
|
||||||
|
|
||||||
|
List<Backup> serviceBackups(final String serviceId) => backups
|
||||||
|
.where((final backup) => backup.serviceId == serviceId)
|
||||||
|
.toList(growable: false);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [
|
List<Object> get props => [
|
||||||
isInitialized,
|
isInitialized,
|
||||||
|
@ -43,7 +47,11 @@ class BackupsState extends ServerInstallationDependendState {
|
||||||
preventActions: preventActions ?? this.preventActions,
|
preventActions: preventActions ?? this.preventActions,
|
||||||
refreshTimer: refreshTimer ?? this.refreshTimer,
|
refreshTimer: refreshTimer ?? this.refreshTimer,
|
||||||
refreshing: refreshing ?? this.refreshing,
|
refreshing: refreshing ?? this.refreshing,
|
||||||
autobackupPeriod: autobackupPeriod ?? this.autobackupPeriod,
|
// 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,
|
backblazeBucket: backblazeBucket ?? this.backblazeBucket,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,8 @@ class ServerJobsState extends ServerInstallationDependendState {
|
||||||
List<ServerJob> get backupJobList => serverJobList
|
List<ServerJob> get backupJobList => serverJobList
|
||||||
.where(
|
.where(
|
||||||
// The backup jobs has the format of 'service.<service_id>.backup'
|
// The backup jobs has the format of 'service.<service_id>.backup'
|
||||||
(final job) => job.typeId.contains('backup'),
|
(final job) =>
|
||||||
|
job.typeId.contains('backup') || job.typeId.contains('restore'),
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue