π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refactor internal logging to use logger extension
Prateek Sunal68714b59ec34
diff --git a/mobile/apps/photos/lib/extensions/logger_extension.dart b/mobile/apps/photos/lib/extensions/logger_extension.dartnew file mode 100644index 0000000000..d70be3df59--- /dev/null+++ b/mobile/apps/photos/lib/extensions/logger_extension.dart@@ -0,0 +1,36 @@+import "package:logging/logging.dart";+import "package:photos/service_locator.dart";++extension LoggerExtension on Logger {+ /// Logs an info message only if the user is an internal user.+ ///+ /// This is useful for debug logging that should only be visible to internal+ /// users during development and testing.+ void internalInfo(String message) {+ if (flagService.internalUser) {+ info(message);+ }+ }++ /// Logs a warning message only if the user is an internal user.+ void internalWarning(+ String message, [+ Object? error,+ StackTrace? stackTrace,+ ]) {+ if (flagService.internalUser) {+ warning(message, error, stackTrace);+ }+ }++ /// Logs a severe message only if the user is an internal user.+ void internalSevere(+ String message, [+ Object? error,+ StackTrace? stackTrace,+ ]) {+ if (flagService.internalUser) {+ severe(message, error, stackTrace);+ }+ }+}diff --git a/mobile/apps/photos/lib/main.dart b/mobile/apps/photos/lib/main.dartindex 26950479fc..36ea3f8c54 100644--- a/mobile/apps/photos/lib/main.dart+++ b/mobile/apps/photos/lib/main.dart@@ -23,6 +23,7 @@ import 'package:photos/core/errors.dart';import 'package:photos/core/network/network.dart';import "package:photos/db/ml/db.dart";import 'package:photos/ente_theme_data.dart';+import "package:photos/extensions/logger_extension.dart";import "package:photos/extensions/stop_watch.dart";import "package:photos/l10n/l10n.dart";import "package:photos/service_locator.dart";@@ -177,44 +178,28 @@ Future<void> _runMinimally(String taskId, TimeLogger tlog) async {// Begin Execution// only runs for android- if (flagService.internalUser) {- _logger.info("[BG TASK] update notification");- }+ _logger.internalInfo("[BG TASK] update notification");updateService.showUpdateNotification().ignore();- if (flagService.internalUser) {- _logger.info("[BG TASK] sync starting");- }+ _logger.internalInfo("[BG TASK] sync starting");await _sync('bgTaskActiveProcess');- if (flagService.internalUser) {- _logger.info("[BG TASK] sync completed");- }+ _logger.internalInfo("[BG TASK] sync completed");- if (flagService.internalUser) {- _logger.info("[BG TASK] locale fetch");- }+ _logger.internalInfo("[BG TASK] locale fetch");final locale = await getLocale();await initializeDateFormatting(locale?.languageCode ?? "en");// only runs for android- if (flagService.internalUser) {- _logger.info("[BG TASK] home widget sync");- }+ _logger.internalInfo("[BG TASK] home widget sync");await _homeWidgetSync(true);// await MLService.instance.init();// await PersonService.init(entityService, MLDataDB.instance, prefs);// await MLService.instance.runAllML(force: true);- if (flagService.internalUser) {- _logger.info("[BG TASK] smart albums sync");- }+ _logger.internalInfo("[BG TASK] smart albums sync");await smartAlbumsService.syncSmartAlbums();- if (flagService.internalUser) {- _logger.info("[BG TASK] $taskId completed");- }+ _logger.internalInfo("[BG TASK] $taskId completed");} catch (e, s) {- if (flagService.internalUser) {- _logger.severe("[BG TASK] $taskId error", e, s);- }+ _logger.internalSevere("[BG TASK] $taskId error", e, s);}}diff --git a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dartindex 677edfa8e7..22107edf1a 100644--- a/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart+++ b/mobile/apps/photos/lib/services/machine_learning/ml_indexing_isolate.dart@@ -212,7 +212,8 @@ class MLIndexingIsolate extends SuperIsolate {final modelName = modelInstance.modelName;final modelPath = await modelInstance.downloadModelSafe();if (modelPath == null) {- _logger.warning("Could not download model '$modelName': WiFi unavailable");+ _logger+ .warning("Could not download model '$modelName': WiFi unavailable");return;}final address = await runInIsolate(IsolateOperation.loadModel, {diff --git a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart b/mobile/apps/photos/lib/services/sync/remote_sync_service.dartindex 743405a944..1a8188858e 100644--- a/mobile/apps/photos/lib/services/sync/remote_sync_service.dart+++ b/mobile/apps/photos/lib/services/sync/remote_sync_service.dart@@ -17,6 +17,7 @@ import 'package:photos/events/files_updated_event.dart';import 'package:photos/events/force_reload_home_gallery_event.dart';import 'package:photos/events/local_photos_updated_event.dart';import 'package:photos/events/sync_status_update_event.dart';+import "package:photos/extensions/logger_extension.dart";import "package:photos/main.dart" show isProcessBg;import 'package:photos/models/device_collection.dart';import "package:photos/models/file/extensions/file_props.dart";@@ -602,173 +603,131 @@ class RemoteSyncService {final int toBeUploaded = filesToBeUploaded.length + updatedFileIDs.length;if (toBeUploaded > 0) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Preparing to upload $toBeUploaded files "- "(${filesToBeUploaded.length} new, ${updatedFileIDs.length} updated) "- "in ${isProcessBg ? 'BACKGROUND' : 'FOREGROUND'} mode",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Preparing to upload $toBeUploaded files "+ "(${filesToBeUploaded.length} new, ${updatedFileIDs.length} updated) "+ "in ${isProcessBg ? 'BACKGROUND' : 'FOREGROUND'} mode",+ );Bus.instance.fire(SyncStatusUpdate(SyncStatus.preparingForUpload, total: toBeUploaded),);- if (flagService.internalUser) {- _logger.info("[UPLOAD-DEBUG] Fired preparingForUpload status update");- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Fired preparingForUpload status update",+ );// Step 1: Verify media location access permission- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Step 1/3: Checking media location access permission...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Step 1/3: Checking media location access permission...",+ );await _uploader.verifyMediaLocationAccess();- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Step 1/3: Media location access verified β",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Step 1/3: Media location access verified β",+ );// Step 2: Check network availability for upload- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Step 2/3: Checking network availability for upload...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Step 2/3: Checking network availability for upload...",+ );await _uploader.checkNetworkForUpload();- if (flagService.internalUser) {- _logger.info("[UPLOAD-DEBUG] Step 2/3: Network check passed β");- }+ _logger.internalInfo("[UPLOAD-DEBUG] Step 2/3: Network check passed β");// Step 3: Fetch upload URLs from server- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Step 3/3: Fetching upload URLs from server for $toBeUploaded files...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Step 3/3: Fetching upload URLs from server for $toBeUploaded files...",+ );await _uploader.fetchUploadURLs(toBeUploaded);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Step 3/3: Upload URLs fetched successfully β",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Step 3/3: Upload URLs fetched successfully β",+ );- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] All pre-upload checks completed successfully! "- "Proceeding to queue individual file uploads...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] All pre-upload checks completed successfully! "+ "Proceeding to queue individual file uploads...",+ );} else {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] No files to upload, skipping upload preparation",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] No files to upload, skipping upload preparation",+ );}final List<Future> futures = [];- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Starting to queue ${filesToBeUploaded.length} new files for upload...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Starting to queue ${filesToBeUploaded.length} new files for upload...",+ );int queuedCount = 0;for (final file in filesToBeUploaded) {if (shouldThrottleUpload &&futures.length >= kMaximumPermissibleUploadsInThrottledMode) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Throttle limit reached (${futures.length} files queued). "- "Skipping remaining ${filesToBeUploaded.length - queuedCount} files.",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Throttle limit reached (${futures.length} files queued). "+ "Skipping remaining ${filesToBeUploaded.length - queuedCount} files.",+ );break;}// prefer existing collection ID for manually uploaded files.// See https://github.com/ente-io/photos-app/pull/187- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Queueing file ${queuedCount + 1}/${filesToBeUploaded.length}: "- "${file.title} (localID: ${file.localID}, generatedID: ${file.generatedID})",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Queueing file ${queuedCount + 1}/${filesToBeUploaded.length}: "+ "${file.title} (localID: ${file.localID}, generatedID: ${file.generatedID})",+ );try {final collectionID = file.collectionID ??(await _collectionsService.getOrCreateForPath(file.deviceFolder ?? 'Unknown Folder',)).id;- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Resolved collectionID: $collectionID for file ${file.title}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Resolved collectionID: $collectionID for file ${file.title}",+ );_uploadFile(file, collectionID, futures);queuedCount++;- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Successfully queued file ${file.title} ($queuedCount queued so far)",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Successfully queued file ${file.title} ($queuedCount queued so far)",+ );} catch (e, s) {- if (flagService.internalUser) {- _logger.severe(- "[UPLOAD-DEBUG] Failed to queue file ${file.title}",- e,- s,- );- }+ _logger.internalSevere(+ "[UPLOAD-DEBUG] Failed to queue file ${file.title}",+ e,+ s,+ );}}- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Finished queueing new files. Total queued: $queuedCount/${filesToBeUploaded.length}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Finished queueing new files. Total queued: $queuedCount/${filesToBeUploaded.length}",+ );- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Starting to queue ${updatedFileIDs.length} updated files for re-upload...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Starting to queue ${updatedFileIDs.length} updated files for re-upload...",+ );int reuploadQueuedCount = 0;for (final uploadedFileID in updatedFileIDs) {if (shouldThrottleUpload &&futures.length >= kMaximumPermissibleUploadsInThrottledMode) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Throttle limit reached for re-uploads (${futures.length} total queued). "- "Skipping remaining ${updatedFileIDs.length - reuploadQueuedCount} updated files.",- );- }- break;- }- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Processing updated file ${reuploadQueuedCount + 1}/${updatedFileIDs.length} "- "(uploadedFileID: $uploadedFileID)",+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Throttle limit reached for re-uploads (${futures.length} total queued). "+ "Skipping remaining ${updatedFileIDs.length - reuploadQueuedCount} updated files.",);+ break;}+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Processing updated file ${reuploadQueuedCount + 1}/${updatedFileIDs.length} "+ "(uploadedFileID: $uploadedFileID)",+ );try {final allFiles = await _db.getFilesInAllCollection(uploadedFileID,ownerID,);if (allFiles.isEmpty) {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] No files found for uploadedFileID $uploadedFileID, skipping",- );- }- continue;- }- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Found ${allFiles.length} file(s) for uploadedFileID $uploadedFileID",+ _logger.internalWarning(+ "[UPLOAD-DEBUG] No files found for uploadedFileID $uploadedFileID, skipping",);+ continue;}+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Found ${allFiles.length} file(s) for uploadedFileID $uploadedFileID",+ );EnteFile? fileInCollectionOwnedByUser;for (final file in allFiles) {if (file.canReUpload(ownerID)) {@@ -777,174 +736,142 @@ class RemoteSyncService {}}if (fileInCollectionOwnedByUser != null) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Queueing re-upload for ${fileInCollectionOwnedByUser.title}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Queueing re-upload for ${fileInCollectionOwnedByUser.title}",+ );_uploadFile(fileInCollectionOwnedByUser,fileInCollectionOwnedByUser.collectionID!,futures,);reuploadQueuedCount++;- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Successfully queued re-upload ($reuploadQueuedCount re-uploads queued)",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Successfully queued re-upload ($reuploadQueuedCount re-uploads queued)",+ );} else {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] No re-uploadable file found for uploadedFileID $uploadedFileID",- );- }- }- } catch (e, s) {- if (flagService.internalUser) {- _logger.severe(- "[UPLOAD-DEBUG] Failed to queue re-upload for uploadedFileID $uploadedFileID",- e,- s,+ _logger.internalWarning(+ "[UPLOAD-DEBUG] No re-uploadable file found for uploadedFileID $uploadedFileID",);}+ } catch (e, s) {+ _logger.internalSevere(+ "[UPLOAD-DEBUG] Failed to queue re-upload for uploadedFileID $uploadedFileID",+ e,+ s,+ );}}- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Finished queueing updated files. Total re-uploads queued: "- "$reuploadQueuedCount/${updatedFileIDs.length}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Finished queueing updated files. Total re-uploads queued: "+ "$reuploadQueuedCount/${updatedFileIDs.length}",+ );- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] βββββββββββββββββββββββββββββββββββββββββββββββββββββββ",- );- _logger.info(- "[UPLOAD-DEBUG] SUMMARY: Total ${futures.length} upload futures queued",- );- _logger.info(- "[UPLOAD-DEBUG] - New files queued: $queuedCount/${filesToBeUploaded.length}",- );- _logger.info(- "[UPLOAD-DEBUG] - Re-uploads queued: $reuploadQueuedCount/${updatedFileIDs.length}",- );- _logger.info(- "[UPLOAD-DEBUG] - Process mode: ${isProcessBg ? 'BACKGROUND' : 'FOREGROUND'}",- );- _logger.info(- "[UPLOAD-DEBUG] Now waiting for all ${futures.length} upload futures to complete...",- );- _logger.info(- "[UPLOAD-DEBUG] βββββββββββββββββββββββββββββββββββββββββββββββββββββββ",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] βββββββββββββββββββββββββββββββββββββββββββββββββββββββ",+ );+ _logger.internalInfo(+ "[UPLOAD-DEBUG] SUMMARY: Total ${futures.length} upload futures queued",+ );+ _logger.internalInfo(+ "[UPLOAD-DEBUG] - New files queued: $queuedCount/${filesToBeUploaded.length}",+ );+ _logger.internalInfo(+ "[UPLOAD-DEBUG] - Re-uploads queued: $reuploadQueuedCount/${updatedFileIDs.length}",+ );+ _logger.internalInfo(+ "[UPLOAD-DEBUG] - Process mode: ${isProcessBg ? 'BACKGROUND' : 'FOREGROUND'}",+ );+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Now waiting for all ${futures.length} upload futures to complete...",+ );+ _logger.internalInfo(+ "[UPLOAD-DEBUG] βββββββββββββββββββββββββββββββββββββββββββββββββββββββ",+ );try {await Future.wait(futures);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] All upload futures completed successfully! "- "Completed: $_completedUploads, Ignored: $_ignoredUploads",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] All upload futures completed successfully! "+ "Completed: $_completedUploads, Ignored: $_ignoredUploads",+ );} on InvalidFileError catch (e, s) {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] InvalidFileError caught (ignored)",- e,- s,- );- }+ _logger.internalWarning(+ "[UPLOAD-DEBUG] InvalidFileError caught (ignored)",+ e,+ s,+ );// Do nothing} on FileSystemException catch (e, s) {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] FileSystemException caught (ignored - likely concurrency issue)",- e,- s,- );- }+ _logger.internalWarning(+ "[UPLOAD-DEBUG] FileSystemException caught (ignored - likely concurrency issue)",+ e,+ s,+ );// Do nothing since it's caused mostly due to concurrency issues// when the foreground app deletes temporary files, interrupting a background// upload} on LockAlreadyAcquiredError catch (e, s) {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] LockAlreadyAcquiredError caught (ignored)",- e,- s,- );- }+ _logger.internalWarning(+ "[UPLOAD-DEBUG] LockAlreadyAcquiredError caught (ignored)",+ e,+ s,+ );// Do nothing} on SilentlyCancelUploadsError catch (e, s) {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] SilentlyCancelUploadsError caught (ignored)",- e,- s,- );- }+ _logger.internalWarning(+ "[UPLOAD-DEBUG] SilentlyCancelUploadsError caught (ignored)",+ e,+ s,+ );// Do nothing} on UserCancelledUploadError catch (e, s) {- if (flagService.internalUser) {- _logger.warning(- "[UPLOAD-DEBUG] UserCancelledUploadError caught (ignored)",- e,- s,- );- }+ _logger.internalWarning(+ "[UPLOAD-DEBUG] UserCancelledUploadError caught (ignored)",+ e,+ s,+ );// Do nothing} catch (e, s) {- if (flagService.internalUser) {- _logger.severe("[UPLOAD-DEBUG] Unexpected error during upload", e, s);- }+ _logger.internalSevere(+ "[UPLOAD-DEBUG] Unexpected error during upload",+ e,+ s,+ );rethrow;}final hasUploaded = _completedUploads > 0;- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Upload process finished. Returning hasUploaded=$hasUploaded "- "(completedUploads: $_completedUploads)",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Upload process finished. Returning hasUploaded=$hasUploaded "+ "(completedUploads: $_completedUploads)",+ );return hasUploaded;}void _uploadFile(EnteFile file, int collectionID, List<Future> futures) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _uploadFile() called for ${file.title} "- "(localID: ${file.localID}, collectionID: $collectionID). "- "Calling FileUploader.upload()...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _uploadFile() called for ${file.title} "+ "(localID: ${file.localID}, collectionID: $collectionID). "+ "Calling FileUploader.upload()...",+ );final future = _uploader.upload(file, collectionID).then((uploadedFile) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Upload completed successfully for ${uploadedFile.title}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Upload completed successfully for ${uploadedFile.title}",+ );return _onFileUploaded(uploadedFile);}).onError((error, stackTrace) {- if (flagService.internalUser) {- _logger.severe(- "[UPLOAD-DEBUG] Upload failed for ${file.title}",- error,- stackTrace,- );- }+ _logger.internalSevere(+ "[UPLOAD-DEBUG] Upload failed for ${file.title}",+ error,+ stackTrace,+ );return _onFileUploadError(error, stackTrace, file);});futures.add(future);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Upload future added to futures list for ${file.title} "- "(futures count: ${futures.length})",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Upload future added to futures list for ${file.title} "+ "(futures count: ${futures.length})",+ );}Future<void> _onFileUploaded(EnteFile file) async {diff --git a/mobile/apps/photos/lib/ui/viewer/people/person_cluster_suggestion.dart b/mobile/apps/photos/lib/ui/viewer/people/person_cluster_suggestion.dartindex 781a41b105..98dab0821e 100644--- a/mobile/apps/photos/lib/ui/viewer/people/person_cluster_suggestion.dart+++ b/mobile/apps/photos/lib/ui/viewer/people/person_cluster_suggestion.dart@@ -66,7 +66,7 @@ class _PersonClustersState extends State<PersonReviewClusterSuggestion> {@overridevoid dispose() {- _peopleChangedEvent?.cancel();+ _peopleChangedEvent?.cancel();super.dispose();}diff --git a/mobile/apps/photos/lib/utils/file_uploader.dart b/mobile/apps/photos/lib/utils/file_uploader.dartindex e318fa8600..5db82d3bf3 100644--- a/mobile/apps/photos/lib/utils/file_uploader.dart+++ b/mobile/apps/photos/lib/utils/file_uploader.dart@@ -23,6 +23,7 @@ import "package:photos/events/file_uploaded_event.dart";import 'package:photos/events/files_updated_event.dart';import 'package:photos/events/local_photos_updated_event.dart';import 'package:photos/events/subscription_purchased_event.dart';+import "package:photos/extensions/logger_extension.dart";import "package:photos/main.dart" show isProcessBg, kLastBGTaskHeartBeatTime;import "package:photos/models/api/metadata.dart";import "package:photos/models/backup/backup_item.dart";@@ -164,32 +165,26 @@ class FileUploader {// upload future will return null as File when the file entry is deleted// locally because it's already present in the destination collection.Future<EnteFile> upload(EnteFile file, int collectionID) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] FileUploader.upload() called for ${file.title} "- "(localID: ${file.localID}, collectionID: $collectionID, "- "isProcessBg: $isProcessBg)",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] FileUploader.upload() called for ${file.title} "+ "(localID: ${file.localID}, collectionID: $collectionID, "+ "isProcessBg: $isProcessBg)",+ );if (file.localID == null || file.localID!.isEmpty) {- if (flagService.internalUser) {- _logger.severe(- "[UPLOAD-DEBUG] Upload rejected - file's localID is null or empty for ${file.title}",- );- }+ _logger.internalSevere(+ "[UPLOAD-DEBUG] Upload rejected - file's localID is null or empty for ${file.title}",+ );return Future.error(Exception("file's localID can not be null or empty"));}// If the file hasn't been queued yet, queue it for upload_totalCountInUploadSession++;final String localID = file.localID!;if (!_queue.containsKey(localID)) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] File ${file.title} not in queue. Adding to upload queue... "- "(queue size before: ${_queue.length})",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] File ${file.title} not in queue. Adding to upload queue... "+ "(queue size before: ${_queue.length})",+ );final completer = Completer<EnteFile>();_queue[localID] = FileUploadItem(file, collectionID, completer);_allBackups[localID] = BackupItem(@@ -199,43 +194,33 @@ class FileUploader {completer: completer,);Bus.instance.fire(BackupUpdatedEvent(_allBackups));- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] File ${file.title} added to queue (queue size: ${_queue.length}). "- "Calling _pollQueue()...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] File ${file.title} added to queue (queue size: ${_queue.length}). "+ "Calling _pollQueue()...",+ );_pollQueue();- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _pollQueue() called for ${file.title}. Returning completer.future",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _pollQueue() called for ${file.title}. Returning completer.future",+ );return completer.future;}// If the file exists in the queue for a matching collectionID,// return the existing future- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] File ${file.title} already in queue with localID $localID",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] File ${file.title} already in queue with localID $localID",+ );final FileUploadItem item = _queue[localID]!;if (item.collectionID == collectionID) {_totalCountInUploadSession--;- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Same collectionID ($collectionID) - returning existing future",- );- }- return item.completer.future;- }- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Different collectionID (existing: ${item.collectionID}, new: $collectionID) "- "- waiting for existing upload to complete",+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Same collectionID ($collectionID) - returning existing future",);+ return item.completer.future;}+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Different collectionID (existing: ${item.collectionID}, new: $collectionID) "+ "- waiting for existing upload to complete",+ );debugPrint("Wait on another upload on same local ID to finish before ""adding it to new collection",@@ -307,65 +292,55 @@ class FileUploader {}void _pollQueue() {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _pollQueue() called. Queue size: ${_queue.length}, "- "uploadCounter: $_uploadCounter/$kMaximumConcurrentUploads, "- "isProcessBg: $isProcessBg",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _pollQueue() called. Queue size: ${_queue.length}, "+ "uploadCounter: $_uploadCounter/$kMaximumConcurrentUploads, "+ "isProcessBg: $isProcessBg",+ );if (SyncService.instance.shouldStopSync()) {- if (flagService.internalUser) {- _logger.warning("[UPLOAD-DEBUG] Sync stop requested - clearing queue");- }+ _logger.internalWarning(+ "[UPLOAD-DEBUG] Sync stop requested - clearing queue",+ );clearQueue(SyncStopRequestedError());return;}if (_queue.isEmpty) {// Upload session completed- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Queue is empty - upload session completed. "- "Resetting totalCountInUploadSession",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Queue is empty - upload session completed. "+ "Resetting totalCountInUploadSession",+ );_totalCountInUploadSession = 0;return;}if (_uploadCounter < kMaximumConcurrentUploads) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Upload capacity available ($_uploadCounter < $kMaximumConcurrentUploads). "- "Searching for pending entry...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Upload capacity available ($_uploadCounter < $kMaximumConcurrentUploads). "+ "Searching for pending entry...",+ );var pendingEntry = _queue.entries.firstWhereOrNull((entry) => entry.value.status == UploadStatus.notStarted,)?.value;- if (flagService.internalUser) {- if (pendingEntry != null) {- _logger.info(- "[UPLOAD-DEBUG] Found pending entry: ${pendingEntry.file.title} "- "(fileType: ${pendingEntry.file.fileType})",- );- } else {- _logger.info("[UPLOAD-DEBUG] No pending entry found in queue");- }+ if (pendingEntry != null) {+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Found pending entry: ${pendingEntry.file.title} "+ "(fileType: ${pendingEntry.file.fileType})",+ );+ } else {+ _logger.internalInfo("[UPLOAD-DEBUG] No pending entry found in queue");}if (pendingEntry != null &&pendingEntry.file.fileType == FileType.video &&_videoUploadCounter >= kMaximumConcurrentVideoUploads) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Video upload limit reached ($_videoUploadCounter >= $kMaximumConcurrentVideoUploads). "- "Looking for non-video entry...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Video upload limit reached ($_videoUploadCounter >= $kMaximumConcurrentVideoUploads). "+ "Looking for non-video entry...",+ );// check if there's any non-video entry which can be queued for uploadpendingEntry = _queue.entries.firstWhereOrNull(@@ -374,23 +349,19 @@ class FileUploader {entry.value.file.fileType != FileType.video,)?.value;- if (flagService.internalUser) {- if (pendingEntry != null) {- _logger.info(- "[UPLOAD-DEBUG] Found non-video entry: ${pendingEntry.file.title}",- );- } else {- _logger.info("[UPLOAD-DEBUG] No non-video entry available");- }+ if (pendingEntry != null) {+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Found non-video entry: ${pendingEntry.file.title}",+ );+ } else {+ _logger.internalInfo("[UPLOAD-DEBUG] No non-video entry available");}}if (pendingEntry != null) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Starting upload for ${pendingEntry.file.title}. "- "Marking as inProgress and calling _encryptAndUploadFileToCollection()...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Starting upload for ${pendingEntry.file.title}. "+ "Marking as inProgress and calling _encryptAndUploadFileToCollection()...",+ );pendingEntry.status = UploadStatus.inProgress;_allBackups[pendingEntry.file.localID!] =_allBackups[pendingEntry.file.localID]!@@ -400,26 +371,20 @@ class FileUploader {pendingEntry.file,pendingEntry.collectionID,);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _encryptAndUploadFileToCollection() initiated for ${pendingEntry.file.title}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _encryptAndUploadFileToCollection() initiated for ${pendingEntry.file.title}",+ );} else {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] No pending entry to process at this time "- "(either all uploads in progress or video limit reached)",- );- }- }- } else {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Upload capacity full ($_uploadCounter >= $kMaximumConcurrentUploads). "- "Waiting for uploads to complete...",+ _logger.internalInfo(+ "[UPLOAD-DEBUG] No pending entry to process at this time "+ "(either all uploads in progress or video limit reached)",);}+ } else {+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Upload capacity full ($_uploadCounter >= $kMaximumConcurrentUploads). "+ "Waiting for uploads to complete...",+ );}}@@ -428,46 +393,36 @@ class FileUploader {int collectionID, {bool forcedUpload = false,}) async {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _encryptAndUploadFileToCollection() started for ${file.title} "- "(collectionID: $collectionID, forcedUpload: $forcedUpload, "- "isProcessBg: $isProcessBg)",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _encryptAndUploadFileToCollection() started for ${file.title} "+ "(collectionID: $collectionID, forcedUpload: $forcedUpload, "+ "isProcessBg: $isProcessBg)",+ );_uploadCounter++;if (file.fileType == FileType.video) {_videoUploadCounter++;}- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Upload counters updated: uploadCounter=$_uploadCounter, "- "videoUploadCounter=$_videoUploadCounter",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Upload counters updated: uploadCounter=$_uploadCounter, "+ "videoUploadCounter=$_videoUploadCounter",+ );final localID = file.localID!;try {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Calling _tryToUpload() for ${file.title} with ${kFileUploadTimeout.inSeconds}s timeout...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Calling _tryToUpload() for ${file.title} with ${kFileUploadTimeout.inSeconds}s timeout...",+ );final uploadedFile =await _tryToUpload(file, collectionID, forcedUpload).timeout(kFileUploadTimeout,onTimeout: () {final message = "Upload timed out for file " + file.toString();- if (flagService.internalUser) {- _logger.warning("[UPLOAD-DEBUG] $message");- }+ _logger.internalWarning("[UPLOAD-DEBUG] $message");throw TimeoutException(message);},);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _tryToUpload() completed successfully for ${file.title}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _tryToUpload() completed successfully for ${file.title}",+ );_queue.remove(localID)!.completer.complete(uploadedFile);_allBackups[localID] =_allBackups[localID]!.copyWith(status: BackupItemStatus.uploaded);@@ -827,40 +782,30 @@ class FileUploader {late String thumbnailObjectKey;if (count <= 1) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Non-multipart upload: Getting thumbnail upload URL...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Non-multipart upload: Getting thumbnail upload URL...",+ );final thumbnailUploadURL = await _getUploadURL();- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Thumbnail URL obtained, uploading thumbnail (size: ${formatBytes(encThumbSize)})...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Thumbnail URL obtained, uploading thumbnail (size: ${formatBytes(encThumbSize)})...",+ );thumbnailObjectKey = await _putFile(thumbnailUploadURL,encryptedThumbnailFile,encThumbSize,);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Thumbnail uploaded successfully! Now getting file upload URL...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Thumbnail uploaded successfully! Now getting file upload URL...",+ );final fileUploadURL = await _getUploadURL();- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] File URL obtained, uploading actual file (size: ${formatBytes(encFileSize)})...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] File URL obtained, uploading actual file (size: ${formatBytes(encFileSize)})...",+ );fileObjectKey =await _putFile(fileUploadURL, encryptedFile, encFileSize);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Actual file uploaded successfully!",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Actual file uploaded successfully!",+ );} else {isMultipartUpload = true;_logger.info(@@ -1478,33 +1423,25 @@ class FileUploader {}Future<UploadURL> _getUploadURL() async {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] _getUploadURL() called. URL queue size: ${_uploadURLs.length}, Upload queue size: ${_queue.length}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] _getUploadURL() called. URL queue size: ${_uploadURLs.length}, Upload queue size: ${_queue.length}",+ );if (_uploadURLs.isEmpty) {- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] URL queue is empty, fetching new upload URLs from server...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] URL queue is empty, fetching new upload URLs from server...",+ );// the queue is empty, fetch at least for one file to handle force uploads// that are not in the queue. This is to also avoidawait fetchUploadURLs(math.max(_queue.length, 1));- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Successfully fetched upload URLs. New queue size: ${_uploadURLs.length}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Successfully fetched upload URLs. New queue size: ${_uploadURLs.length}",+ );}try {final url = _uploadURLs.removeFirst();- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] Returning upload URL. Remaining URLs in queue: ${_uploadURLs.length}",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] Returning upload URL. Remaining URLs in queue: ${_uploadURLs.length}",+ );return url;} catch (e) {if (e is StateError && e.message == 'No element' && _queue.isEmpty) {@@ -1522,31 +1459,25 @@ class FileUploader {_uploadURLFetchInProgress ??= Future<void>(() async {try {final requestCount = math.min(42, fileCount * 2);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] fetchUploadURLs() starting HTTP GET to /files/upload-urls with count=$requestCount",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] fetchUploadURLs() starting HTTP GET to /files/upload-urls with count=$requestCount",+ );final response = await _enteDio.get("/files/upload-urls",queryParameters: {"count": requestCount, // m4gic number},);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] HTTP GET completed, parsing ${(response.data["urls"] as List).length} URLs...",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] HTTP GET completed, parsing ${(response.data["urls"] as List).length} URLs...",+ );final urls = (response.data["urls"] as List).map((e) => UploadURL.fromMap(e)).toList();_uploadURLs.addAll(urls);- if (flagService.internalUser) {- _logger.info(- "[UPLOAD-DEBUG] fetchUploadURLs() completed. Added ${urls.length} URLs to queue.",- );- }+ _logger.internalInfo(+ "[UPLOAD-DEBUG] fetchUploadURLs() completed. Added ${urls.length} URLs to queue.",+ );} on DioException catch (e, s) {if (e.response != null) {if (e.response!.statusCode == 402) {