Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Refactor

Neeraj Guptac1ddb863ad55
diff --git a/mobile/lib/module/download/manager.dart b/mobile/lib/module/download/manager.dart
index 25c94a68ed..6d826b0bc8 100644
--- a/mobile/lib/module/download/manager.dart
+++ b/mobile/lib/module/download/manager.dart
@@ -7,6 +7,7 @@ import "package:photos/core/configuration.dart";
import "package:photos/module/download/file_url.dart";
import "package:photos/module/download/task.dart";
+import "package:photos/service_locator.dart";
class DownloadManager {
final _logger = Logger('DownloadManager');
@@ -30,6 +31,11 @@ class DownloadManager {
return _streams[fileId]!.stream;
}
+ bool enableResumableDownload(int? size) {
+ if (size == null) return false;
+ return size > downloadChunkSize && flagService.internalUser;
+ }
+
/// Start download and return a Future that completes when download finishes
/// If download was paused, calling this again will resume it
Future<DownloadResult> download(
@@ -100,8 +106,6 @@ class DownloadManager {
_updateTask(task.copyWith(status: DownloadStatus.paused));
}
- // Future will be completed in _startDownload's DioException handling
-
// Clean up streams if no listeners
final stream = _streams[fileId];
if (stream != null && !stream.hasListener) {
@@ -123,9 +127,6 @@ class DownloadManager {
_updateTask(task.copyWith(status: DownloadStatus.cancelled));
_tasks.remove(fileId);
}
-
- // Future will be completed in _startDownload's DioException handling
-
_cleanup(fileId);
}
@@ -163,8 +164,6 @@ class DownloadManager {
);
_updateTask(task);
- // Download missing chunks
- // log existing progress and download bytes
_logger.info(
'Resuming download for ${task.filename} (${task.bytesDownloaded}/${task.totalBytes} bytes)',
);
@@ -172,7 +171,6 @@ class DownloadManager {
if (existingChunks[i] || cancelToken.isCancelled) continue;
_logger.info('Downloading chunk ${i + 1} of $totalChunks');
await _downloadChunk(task, basePath, i, totalChunks, cancelToken);
- _logger.info('Chunk ${i + 1} downloaded');
existingChunks[i] = true;
}
@@ -316,7 +314,6 @@ class DownloadManager {
try {
final directory = Configuration.instance.getTempDirectory();
final basePath = '$directory${task.id}.encrypted';
- // Delete final file
final finalFile = File(basePath);
if (await finalFile.exists()) await finalFile.delete();
diff --git a/mobile/lib/utils/file_download_util.dart b/mobile/lib/utils/file_download_util.dart
index d67caf58b7..267ad8ed96 100644
--- a/mobile/lib/utils/file_download_util.dart
+++ b/mobile/lib/utils/file_download_util.dart
@@ -98,8 +98,6 @@ Future<File?> downloadAndDecryptPublicFile(
}
}
-String lastProgress = "";
-
Future<File?> downloadAndDecrypt(
EnteFile file, {
ProgressCallback? progressCallback,
@@ -125,9 +123,7 @@ Future<File?> downloadAndDecrypt(
final startTime = DateTime.now().millisecondsSinceEpoch;
try {
- // check if great than 10MB
- if (file.fileSize != null &&
- file.fileSize! > DownloadManager.downloadChunkSize) {
+ if (downloadManager.enableResumableDownload(file.fileSize)) {
final DownloadResult result = await downloadManager.download(
file.uploadedFileID!,
file.displayName,