Revert "remove unneeded allElectronAPIsExist check"
This reverts commit 96edd9384d
.
This commit is contained in:
parent
2386273767
commit
37a3d551bf
|
@ -4,37 +4,46 @@ import { runningInBrowser } from 'utils/common';
|
||||||
|
|
||||||
class ImportService {
|
class ImportService {
|
||||||
ElectronAPIs: any;
|
ElectronAPIs: any;
|
||||||
|
private allElectronAPIsExist: boolean = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
|
||||||
|
this.allElectronAPIsExist = !!this.ElectronAPIs?.exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
async showUploadFilesDialog(): Promise<ElectronFile[]> {
|
async showUploadFilesDialog(): Promise<ElectronFile[]> {
|
||||||
return this.ElectronAPIs.showUploadFilesDialog();
|
if (this.allElectronAPIsExist) {
|
||||||
|
return this.ElectronAPIs.showUploadFilesDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async showUploadDirsDialog(): Promise<ElectronFile[]> {
|
async showUploadDirsDialog(): Promise<ElectronFile[]> {
|
||||||
return this.ElectronAPIs.showUploadDirsDialog();
|
if (this.allElectronAPIsExist) {
|
||||||
|
return this.ElectronAPIs.showUploadDirsDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPendingUploads() {
|
async getPendingUploads() {
|
||||||
const { files, collectionName } =
|
if (this.allElectronAPIsExist) {
|
||||||
(await this.ElectronAPIs.getPendingUploads()) as {
|
const { files, collectionName } =
|
||||||
files: ElectronFile[];
|
(await this.ElectronAPIs.getPendingUploads()) as {
|
||||||
collectionName: string;
|
files: ElectronFile[];
|
||||||
|
collectionName: string;
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
files,
|
||||||
|
collectionName,
|
||||||
};
|
};
|
||||||
return {
|
}
|
||||||
files,
|
|
||||||
collectionName,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setToUploadFiles(
|
async setToUploadFiles(
|
||||||
files: FileWithCollection[],
|
files: FileWithCollection[],
|
||||||
collections: Collection[]
|
collections: Collection[]
|
||||||
) {
|
) {
|
||||||
let collectionName: string;
|
if (this.allElectronAPIsExist) {
|
||||||
/* collection being one suggest one of two things
|
let collectionName: string;
|
||||||
|
/* collection being one suggest one of two things
|
||||||
1. Either the user has upload to a single existing collection
|
1. Either the user has upload to a single existing collection
|
||||||
2. Created a new single collection to upload to
|
2. Created a new single collection to upload to
|
||||||
may have had multiple folder, but chose to upload
|
may have had multiple folder, but chose to upload
|
||||||
|
@ -42,30 +51,41 @@ class ImportService {
|
||||||
hence saving the collection name when upload collection count is 1
|
hence saving the collection name when upload collection count is 1
|
||||||
helps the info of user choosing this options
|
helps the info of user choosing this options
|
||||||
and on next upload we can directly start uploading to this collection
|
and on next upload we can directly start uploading to this collection
|
||||||
*/
|
*/
|
||||||
if (collections.length === 1) {
|
if (collections.length === 1) {
|
||||||
collectionName = collections[0].name;
|
collectionName = collections[0].name;
|
||||||
}
|
|
||||||
const filePaths = files.map((file) => (file.file as ElectronFile).path);
|
|
||||||
this.ElectronAPIs.setToUploadFiles(filePaths);
|
|
||||||
this.ElectronAPIs.setToUploadCollection(collectionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
const filePaths = files.map(
|
||||||
|
(file) => (file.file as ElectronFile).path
|
||||||
|
);
|
||||||
|
this.ElectronAPIs.setToUploadFiles(filePaths);
|
||||||
|
this.ElectronAPIs.setToUploadCollection(collectionName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updatePendingUploads(files: FileWithCollection[]) {
|
||||||
|
if (this.allElectronAPIsExist) {
|
||||||
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.ElectronAPIs.setToUploadFiles(filePaths);
|
||||||
}
|
}
|
||||||
this.ElectronAPIs.setToUploadFiles(filePaths);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new ImportService();
|
export default new ImportService();
|
||||||
|
|
Loading…
Reference in a new issue