Skip to content

armgit / ente

Public Imported from GitHub
0

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

Refactor

Neeraj Gupta2b32cd4277e8
diff --git a/mobile/lib/models/file/file.dart b/mobile/lib/models/file/file.dart
index 52d501d3f7..2dd77bf6c6 100644
--- a/mobile/lib/models/file/file.dart
+++ b/mobile/lib/models/file/file.dart
@@ -9,6 +9,7 @@ import 'package:photos/core/constants.dart';
import 'package:photos/models/file/file_type.dart';
import 'package:photos/models/location/location.dart';
import "package:photos/models/metadata/file_magic.dart";
+import "package:photos/module/download/file_url.dart";
import "package:photos/service_locator.dart";
import 'package:photos/utils/exif_util.dart';
import 'package:photos/utils/file_uploader_util.dart';
@@ -242,47 +243,8 @@ class EnteFile {
return metadata;
}
- String get downloadUrl {
- final endpoint = Configuration.instance.getHttpEndpoint();
- if (disableWorker) {
- return endpoint + "/files/download/" + uploadedFileID.toString();
- } else {
- return "https://files.ente.io/?fileID=" + uploadedFileID.toString();
- }
- }
-
- String get publicDownloadUrl {
- final endpoint = Configuration.instance.getHttpEndpoint();
- if (disableWorker) {
- return endpoint + "/public-collection/files/download/${uploadedFileID!}";
- } else {
- return "https://public-albums.ente.io/download/?fileID=$uploadedFileID";
- }
- }
-
- String get thumbnailUrl {
- final endpoint = Configuration.instance.getHttpEndpoint();
- if (disableWorker) {
- return endpoint + "/files/preview/$uploadedFileID";
- } else {
- return "https://thumbnails.ente.io/?fileID=$uploadedFileID";
- }
- }
-
- bool get disableWorker {
- final endpoint = Configuration.instance.getHttpEndpoint();
- return endpoint != kDefaultProductionEndpoint ||
- flagService.disableCFWorker;
- }
-
- String get pubThumbUrl {
- final endpoint = Configuration.instance.getHttpEndpoint();
- if (disableWorker) {
- return endpoint + "/public-collection/files/preview/$uploadedFileID";
- } else {
- return "https://public-albums.ente.io/preview/?fileID=$uploadedFileID";
- }
- }
+ String get downloadUrl =>
+ FileUrl.getUrl(uploadedFileID!, FileUrlType.download);
String? get caption {
return pubMagicMetadata?.caption;
diff --git a/mobile/lib/module/download/file_url.dart b/mobile/lib/module/download/file_url.dart
new file mode 100644
index 0000000000..eed4398cec
--- /dev/null
+++ b/mobile/lib/module/download/file_url.dart
@@ -0,0 +1,40 @@
+import "package:photos/core/configuration.dart";
+import "package:photos/core/constants.dart";
+import "package:photos/service_locator.dart";
+
+enum FileUrlType {
+ download,
+ publicDownload,
+ thumbnail,
+ publicThumbnail,
+}
+
+class FileUrl {
+ static String getUrl(int fileID, FileUrlType type) {
+ final endpoint = Configuration.instance.getHttpEndpoint();
+ final disableWorker =
+ endpoint != kDefaultProductionEndpoint || flagService.disableCFWorker;
+
+ switch (type) {
+ case FileUrlType.download:
+ return disableWorker
+ ? "$endpoint/files/download/$fileID"
+ : "https://files.ente.io/?fileID=$fileID";
+
+ case FileUrlType.publicDownload:
+ return disableWorker
+ ? "$endpoint/public-collection/files/download/$fileID"
+ : "https://public-albums.ente.io/download/?fileID=$fileID";
+
+ case FileUrlType.thumbnail:
+ return disableWorker
+ ? "$endpoint/files/preview/$fileID"
+ : "https://thumbnails.ente.io/?fileID=$fileID";
+
+ case FileUrlType.publicThumbnail:
+ return disableWorker
+ ? "$endpoint/public-collection/files/preview/$fileID"
+ : "https://public-albums.ente.io/preview/?fileID=$fileID";
+ }
+ }
+}
diff --git a/mobile/lib/utils/file_download_util.dart b/mobile/lib/utils/file_download_util.dart
index caeb1d50ba..ed7909247a 100644
--- a/mobile/lib/utils/file_download_util.dart
+++ b/mobile/lib/utils/file_download_util.dart
@@ -15,6 +15,7 @@ import "package:photos/events/local_photos_updated_event.dart";
import 'package:photos/models/file/file.dart';
import "package:photos/models/file/file_type.dart";
import "package:photos/models/ignored_file.dart";
+import "package:photos/module/download/file_url.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/services/ignored_files_service.dart";
import "package:photos/services/sync/local_sync_service.dart";
@@ -47,7 +48,7 @@ Future<File?> downloadAndDecryptPublicFile(
if (authJWTToken != null) "X-Auth-Access-Token-JWT": authJWTToken,
};
final response = (await NetworkClient.instance.getDio().download(
- file.publicDownloadUrl,
+ FileUrl.getUrl(file.uploadedFileID!, FileUrlType.publicDownload),
encryptedFilePath,
options: Options(
headers: headers,
diff --git a/mobile/lib/utils/thumbnail_util.dart b/mobile/lib/utils/thumbnail_util.dart
index 1bd1d0b0c5..169137e880 100644
--- a/mobile/lib/utils/thumbnail_util.dart
+++ b/mobile/lib/utils/thumbnail_util.dart
@@ -13,6 +13,7 @@ import 'package:photos/core/constants.dart';
import 'package:photos/core/errors.dart';
import 'package:photos/core/network/network.dart';
import 'package:photos/models/file/file.dart';
+import "package:photos/module/download/file_url.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/utils/file_key.dart";
import 'package:photos/utils/file_uploader_util.dart';
@@ -173,7 +174,10 @@ Future<void> _downloadAndDecryptThumbnail(FileDownloadItem item) async {
};
encryptedThumbnail = (await NetworkClient.instance.getDio().get(
- file.pubThumbUrl,
+ FileUrl.getUrl(
+ file.uploadedFileID!,
+ FileUrlType.publicThumbnail,
+ ),
options: Options(
headers: headers,
responseType: ResponseType.bytes,
@@ -182,7 +186,10 @@ Future<void> _downloadAndDecryptThumbnail(FileDownloadItem item) async {
.data;
} else {
encryptedThumbnail = (await NetworkClient.instance.getDio().get(
- file.thumbnailUrl,
+ FileUrl.getUrl(
+ file.uploadedFileID!,
+ FileUrlType.thumbnail,
+ ),
options: Options(
headers: {"X-Auth-Token": Configuration.instance.getToken()},
responseType: ResponseType.bytes,