Skip to content

armgit / ente

Public Imported from GitHub
0

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

Unclass

Manav Rathi04f32d64f18a
diff --git a/web/apps/photos/src/components/Upload/Uploader.tsx b/web/apps/photos/src/components/Upload/Uploader.tsx
index 731b9b5f43..1d95c9310e 100644
--- a/web/apps/photos/src/components/Upload/Uploader.tsx
+++ b/web/apps/photos/src/components/Upload/Uploader.tsx
@@ -17,7 +17,7 @@ import { GalleryContext } from "pages/gallery";
import { useContext, useEffect, useRef, useState } from "react";
import billingService from "services/billingService";
import { getLatestCollections } from "services/collectionService";
-import ImportService from "services/importService";
+import { setToUploadCollection } from "services/pending-uploads";
import {
getPublicCollectionUID,
getPublicCollectionUploaderName,
@@ -513,17 +513,17 @@ export default function Uploader(props: Props) {
!isPendingDesktopUpload.current &&
!watcher.isUploadRunning()
) {
- await ImportService.setToUploadCollection(collections);
+ await setToUploadCollection(collections);
// TODO (MR): What happens when we have both?
if (zipPaths.current) {
- await electron.setToUploadFiles(
- PICKED_UPLOAD_TYPE.ZIPS,
+ await electron.setPendingUploadFiles(
+ "zips",
zipPaths.current,
);
zipPaths.current = null;
}
- await electron.setToUploadFiles(
- PICKED_UPLOAD_TYPE.FILES,
+ await electron.setPendingUploadFiles(
+ "files",
filesWithCollectionToUploadIn.map(
({ file }) => (file as ElectronFile).path,
),
diff --git a/web/apps/photos/src/services/importService.ts b/web/apps/photos/src/services/importService.ts
deleted file mode 100644
index de5e4cfa6b..0000000000
--- a/web/apps/photos/src/services/importService.ts
+++ /dev/null
@@ -1,48 +0,0 @@
-import { ensureElectron } from "@/next/electron";
-import { Collection } from "types/collection";
-import { ElectronFile, FileWithCollection } from "types/upload";
-
-class ImportService {
- async setToUploadCollection(collections: Collection[]) {
- let collectionName: string = null;
- /* collection being one suggest one of two things
- 1. Either the user has upload to a single existing collection
- 2. Created a new single collection to upload to
- may have had multiple folder, but chose to upload
- to one album
- hence saving the collection name when upload collection count is 1
- helps the info of user choosing this options
- and on next upload we can directly start uploading to this collection
- */
- if (collections.length === 1) {
- collectionName = collections[0].name;
- }
- await ensureElectron().setPendingUploadCollection(collectionName);
- }
-
- async updatePendingUploads(files: FileWithCollection[]) {
- const filePaths = [];
- for (const fileWithCollection of files) {
- if (fileWithCollection.isLivePhoto) {
- filePaths.push(
- (fileWithCollection.livePhotoAssets.image as ElectronFile)
- .path,
- (fileWithCollection.livePhotoAssets.video as ElectronFile)
- .path,
- );
- } else {
- filePaths.push((fileWithCollection.file as ElectronFile).path);
- }
- }
- await ensureElectron().setPendingUploadFiles("files", filePaths);
- }
-
- async cancelRemainingUploads() {
- const electron = ensureElectron();
- await electron.setPendingUploadCollection(undefined);
- await electron.setPendingUploadFiles("zips", []);
- await electron.setPendingUploadFiles("files", []);
- }
-}
-
-export default new ImportService();
diff --git a/web/apps/photos/src/services/pending-uploads.ts b/web/apps/photos/src/services/pending-uploads.ts
new file mode 100644
index 0000000000..3b219f5b0c
--- /dev/null
+++ b/web/apps/photos/src/services/pending-uploads.ts
@@ -0,0 +1,42 @@
+import { ensureElectron } from "@/next/electron";
+import { Collection } from "types/collection";
+import { ElectronFile, FileWithCollection } from "types/upload";
+
+export const setToUploadCollection = async (collections: Collection[]) => {
+ let collectionName: string = null;
+ /* collection being one suggest one of two things
+ 1. Either the user has upload to a single existing collection
+ 2. Created a new single collection to upload to
+ may have had multiple folder, but chose to upload
+ to one album
+ hence saving the collection name when upload collection count is 1
+ helps the info of user choosing this options
+ and on next upload we can directly start uploading to this collection
+ */
+ if (collections.length === 1) {
+ collectionName = collections[0].name;
+ }
+ await ensureElectron().setPendingUploadCollection(collectionName);
+};
+
+export const updatePendingUploads = async (files: FileWithCollection[]) => {
+ const filePaths = [];
+ for (const fileWithCollection of files) {
+ if (fileWithCollection.isLivePhoto) {
+ filePaths.push(
+ (fileWithCollection.livePhotoAssets.image as ElectronFile).path,
+ (fileWithCollection.livePhotoAssets.video as ElectronFile).path,
+ );
+ } else {
+ filePaths.push((fileWithCollection.file as ElectronFile).path);
+ }
+ }
+ await ensureElectron().setPendingUploadFiles("files", filePaths);
+};
+
+export const cancelRemainingUploads = async () => {
+ const electron = ensureElectron();
+ await electron.setPendingUploadCollection(undefined);
+ await electron.setPendingUploadFiles("zips", []);
+ await electron.setPendingUploadFiles("files", []);
+};
diff --git a/web/apps/photos/src/services/upload/uploadManager.ts b/web/apps/photos/src/services/upload/uploadManager.ts
index c1fa657562..8f72343193 100644
--- a/web/apps/photos/src/services/upload/uploadManager.ts
+++ b/web/apps/photos/src/services/upload/uploadManager.ts
@@ -8,7 +8,10 @@ import { Events, eventBus } from "@ente/shared/events";
import { Remote } from "comlink";
import { UPLOAD_RESULT, UPLOAD_STAGES } from "constants/upload";
import isElectron from "is-electron";
-import ImportService from "services/importService";
+import {
+ cancelRemainingUploads,
+ updatePendingUploads,
+} from "services/pending-uploads";
import {
getLocalPublicFiles,
getPublicCollectionUID,
@@ -177,7 +180,7 @@ class UploadManager {
if (e.message === CustomError.UPLOAD_CANCELLED) {
if (isElectron()) {
this.remainingFiles = [];
- await ImportService.cancelRemainingUploads();
+ await cancelRemainingUploads();
}
} else {
log.error("uploading failed with error", e);
@@ -431,7 +434,7 @@ class UploadManager {
this.remainingFiles = this.remainingFiles.filter(
(file) => !areFileWithCollectionsSame(file, fileWithCollection),
);
- await ImportService.updatePendingUploads(this.remainingFiles);
+ await updatePendingUploads(this.remainingFiles);
}
}