mirror of
https://github.com/immich-app/immich.git
synced 2025-11-21 21:40:41 +09:00
Some checks failed
CodeQL / Analyze (javascript) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Docker / pre-job (push) Has been cancelled
Docs build / pre-job (push) Has been cancelled
Static Code Analysis / pre-job (push) Has been cancelled
Test / pre-job (push) Has been cancelled
Test / ShellCheck (push) Has been cancelled
Test / OpenAPI Clients (push) Has been cancelled
Test / TypeORM Checks (push) Has been cancelled
Docker / Re-Tag ML () (push) Has been cancelled
Docker / Re-Tag ML (-armnn) (push) Has been cancelled
Docker / Re-Tag ML (-cuda) (push) Has been cancelled
Docker / Re-Tag ML (-openvino) (push) Has been cancelled
Docker / Re-Tag Server () (push) Has been cancelled
Docker / Build and Push ML (armnn, linux/arm64, -armnn) (push) Has been cancelled
Docker / Build and Push ML (cpu, linux/amd64,linux/arm64) (push) Has been cancelled
Docker / Build and Push ML (cuda, linux/amd64, -cuda) (push) Has been cancelled
Docker / Build and Push ML (openvino, linux/amd64, -openvino) (push) Has been cancelled
Docker / Build and Push Server (cpu, linux/amd64,linux/arm64) (push) Has been cancelled
Docker / Docker Build & Push Server Success (push) Has been cancelled
Docker / Docker Build & Push ML Success (push) Has been cancelled
Docs build / Docs Build (push) Has been cancelled
Static Code Analysis / Run Dart Code Analysis (push) Has been cancelled
Test / Test & Lint Server (push) Has been cancelled
Test / Unit Test CLI (push) Has been cancelled
Test / Unit Test CLI (Windows) (push) Has been cancelled
Test / Test & Lint Web (push) Has been cancelled
Test / End-to-End Lint (push) Has been cancelled
Test / Medium Tests (Server) (push) Has been cancelled
Test / End-to-End Tests (Server & CLI) (push) Has been cancelled
Test / End-to-End Tests (Web) (push) Has been cancelled
Test / Unit Test Mobile (push) Has been cancelled
Test / Unit Test ML (push) Has been cancelled
110 lines
3.3 KiB
Dart
110 lines
3.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:immich_mobile/providers/backup/backup.provider.dart';
|
|
import 'package:immich_mobile/services/backup_verification.service.dart';
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
|
import 'package:immich_mobile/providers/asset.provider.dart';
|
|
import 'package:immich_mobile/widgets/common/confirm_dialog.dart';
|
|
import 'package:immich_mobile/widgets/common/immich_toast.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:wakelock_plus/wakelock_plus.dart';
|
|
|
|
part 'backup_verification.provider.g.dart';
|
|
|
|
@riverpod
|
|
class BackupVerification extends _$BackupVerification {
|
|
@override
|
|
bool build() => false;
|
|
|
|
void performBackupCheck(BuildContext context) async {
|
|
try {
|
|
state = true;
|
|
final backupState = ref.read(backupProvider);
|
|
|
|
if (backupState.allUniqueAssets.length >
|
|
backupState.selectedAlbumsBackupAssetsIds.length) {
|
|
if (context.mounted) {
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: "Backup all assets before starting this check!",
|
|
toastType: ToastType.error,
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
final connection = await Connectivity().checkConnectivity();
|
|
if (!connection.contains(ConnectivityResult.wifi)) {
|
|
if (context.mounted) {
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: "Make sure to be connected to unmetered Wi-Fi",
|
|
toastType: ToastType.error,
|
|
);
|
|
}
|
|
return;
|
|
}
|
|
WakelockPlus.enable();
|
|
|
|
const limit = 100;
|
|
final toDelete = await ref
|
|
.read(backupVerificationServiceProvider)
|
|
.findWronglyBackedUpAssets(limit: limit);
|
|
if (toDelete.isEmpty) {
|
|
if (context.mounted) {
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: "Did not find any corrupt asset backups!",
|
|
toastType: ToastType.success,
|
|
);
|
|
}
|
|
} else {
|
|
if (context.mounted) {
|
|
await showDialog(
|
|
context: context,
|
|
builder: (ctx) => ConfirmDialog(
|
|
onOk: () => _performDeletion(context, toDelete),
|
|
title: "Corrupt backups!",
|
|
ok: "Delete",
|
|
content:
|
|
"Found ${toDelete.length} (max $limit at once) corrupt asset backups. "
|
|
"Run the check again to find more.\n"
|
|
"Do you want to delete the corrupt asset backups now?",
|
|
),
|
|
);
|
|
}
|
|
}
|
|
} finally {
|
|
WakelockPlus.disable();
|
|
state = false;
|
|
}
|
|
}
|
|
|
|
Future<void> _performDeletion(
|
|
BuildContext context,
|
|
List<Asset> assets,
|
|
) async {
|
|
try {
|
|
state = true;
|
|
if (context.mounted) {
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: "Deleting ${assets.length} assets on the server...",
|
|
);
|
|
}
|
|
await ref.read(assetProvider.notifier).deleteAssets(assets, force: true);
|
|
if (context.mounted) {
|
|
ImmichToast.show(
|
|
context: context,
|
|
msg: "Deleted ${assets.length} assets on the server. "
|
|
"You can now start a manual backup",
|
|
toastType: ToastType.success,
|
|
);
|
|
}
|
|
} finally {
|
|
state = false;
|
|
}
|
|
}
|
|
}
|