[mob][photos] Fix for PlatformException in video thumbnails

This commit is contained in:
laurenspriem 2024-05-24 17:48:03 +05:30
parent b1e0c83733
commit 302890baef
2 changed files with 30 additions and 2 deletions

View file

@ -8,6 +8,18 @@ class GeneralFaceMlException implements Exception {
String toString() => 'GeneralFaceMlException: $message'; String toString() => 'GeneralFaceMlException: $message';
} }
class ThumbnailRetrievalException implements Exception {
final String message;
final StackTrace stackTrace;
ThumbnailRetrievalException(this.message, this.stackTrace);
@override
String toString() {
return 'ThumbnailRetrievalException: $message\n$stackTrace';
}
}
class CouldNotRetrieveAnyFileData implements Exception {} class CouldNotRetrieveAnyFileData implements Exception {}
class CouldNotInitializeFaceDetector implements Exception {} class CouldNotInitializeFaceDetector implements Exception {}

View file

@ -9,6 +9,7 @@ import "dart:ui" show Image;
import "package:computer/computer.dart"; import "package:computer/computer.dart";
import "package:dart_ui_isolate/dart_ui_isolate.dart"; import "package:dart_ui_isolate/dart_ui_isolate.dart";
import "package:flutter/foundation.dart" show debugPrint, kDebugMode; import "package:flutter/foundation.dart" show debugPrint, kDebugMode;
import "package:flutter/services.dart";
import "package:logging/logging.dart"; import "package:logging/logging.dart";
import "package:onnxruntime/onnxruntime.dart"; import "package:onnxruntime/onnxruntime.dart";
import "package:package_info_plus/package_info_plus.dart"; import "package:package_info_plus/package_info_plus.dart";
@ -446,7 +447,8 @@ class FaceMlService {
if (LocalSettings.instance.remoteFetchEnabled) { if (LocalSettings.instance.remoteFetchEnabled) {
try { try {
final Set<int> fileIds = {}; // if there are duplicates here server returns 400 final Set<int> fileIds =
{}; // if there are duplicates here server returns 400
// Try to find embeddings on the remote server // Try to find embeddings on the remote server
for (final f in chunk) { for (final f in chunk) {
fileIds.add(f.uploadedFileID!); fileIds.add(f.uploadedFileID!);
@ -844,13 +846,22 @@ class FaceMlService {
} }
await FaceMLDataDB.instance.bulkInsertFaces(faces); await FaceMLDataDB.instance.bulkInsertFaces(faces);
return true; return true;
} on ThumbnailRetrievalException catch (e, s) {
_logger.severe(
'ThumbnailRetrievalException while processing image with ID ${enteFile.uploadedFileID}, storing empty face so indexing does not get stuck',
e,
s,
);
await FaceMLDataDB.instance
.bulkInsertFaces([Face.empty(enteFile.uploadedFileID!, error: true)]);
return true;
} catch (e, s) { } catch (e, s) {
_logger.severe( _logger.severe(
"Failed to analyze using FaceML for image with ID: ${enteFile.uploadedFileID}", "Failed to analyze using FaceML for image with ID: ${enteFile.uploadedFileID}",
e, e,
s, s,
); );
return true; return false;
} }
} }
@ -1004,7 +1015,12 @@ class FaceMlService {
final stopwatch = Stopwatch()..start(); final stopwatch = Stopwatch()..start();
File? file; File? file;
if (enteFile.fileType == FileType.video) { if (enteFile.fileType == FileType.video) {
try {
file = await getThumbnailForUploadedFile(enteFile); file = await getThumbnailForUploadedFile(enteFile);
} on PlatformException catch (e, s) {
_logger.severe("Could not get thumbnail for $enteFile due to PlatformException", e, s);
throw ThumbnailRetrievalException(e.toString(), s);
}
} else { } else {
file = await getFile(enteFile, isOrigin: true); file = await getFile(enteFile, isOrigin: true);
// TODO: This is returning null for Pragadees for all files, so something is wrong here! // TODO: This is returning null for Pragadees for all files, so something is wrong here!