π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Refresh stale device file paths for OCR
laurenspriem5943e63e5d4b
diff --git a/mobile/apps/photos/lib/services/machine_learning/ocr_service.dart b/mobile/apps/photos/lib/services/machine_learning/ocr_service.dartindex 9cb2665efa..3de747b969 100644--- a/mobile/apps/photos/lib/services/machine_learning/ocr_service.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ocr_service.dart@@ -3,6 +3,9 @@ import "dart:io";import "package:flutter/widgets.dart";import "package:logging/logging.dart";+import "package:photos/models/file/extensions/file_props.dart";+import "package:photos/models/file/file.dart";+import "package:photos/module/download/file.dart";import "package:photos/services/machine_learning/ocr/ocr_backend.dart";import "package:photos/services/machine_learning/ocr/ocr_models.dart";import "package:photos/services/machine_learning/ocr/rust_ocr_backend.dart";@@ -210,6 +213,31 @@ class OcrService with WidgetsBindingObserver {return _backend.ensureDisplayablePath(imagePath);}+ Future<File?> resolveImageFile(EnteFile file) async {+ final localFile = await getFile(file);+ if (localFile != null && await localFile.exists()) return localFile;+ if (file.localID == null ||+ file.isSharedMediaToAppSandbox ||+ file.isDeviceTrash) {+ return null;+ }+ try {+ final asset = await file.getAsset;+ if (asset == null || !await asset.exists) return null;+ final refreshedFile = await asset.file;+ return refreshedFile != null && await refreshedFile.exists()+ ? refreshedFile+ : null;+ } catch (error, stackTrace) {+ _logger.warning(+ "Could not refresh device image for OCR",+ error,+ stackTrace,+ );+ return null;+ }+ }+OcrBackend _createBackend(OcrBackendKind kind) => switch (kind) {OcrBackendKind.rust => _createRustBackend(),OcrBackendKind.vision => _createVisionBackend(),diff --git a/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart b/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dartindex a3e79fd2a3..41188e6574 100644--- a/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart+++ b/mobile/apps/photos/lib/ui/viewer/file/ocr/inline_text_detection.dart@@ -419,7 +419,7 @@ class _InlineTextDetectionState extends State<InlineTextDetection> {Future<File?> _resolveStillImage(int generation) async {final file = widget.file;final canUseUploadedCopy = file.isUploaded && !file.isRemoteOnlyFile;- File? localFile = await getFile(file);+ File? localFile = await _ocrService.resolveImageFile(file);if (!mounted || generation != _evaluationGeneration) return null;if (canUseUploadedCopy && (localFile == null || !localFile.existsSync())) {localFile = await getFileFromServer(file);