Unclass
This commit is contained in:
parent
4d80dc3af9
commit
04f32d64f1
|
@ -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,
|
||||
),
|
||||
|
|
|
@ -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();
|
42
web/apps/photos/src/services/pending-uploads.ts
Normal file
42
web/apps/photos/src/services/pending-uploads.ts
Normal file
|
@ -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", []);
|
||||
};
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue