support for uploading google photos zip

This commit is contained in:
Rushikesh Tote 2022-04-01 13:20:08 +05:30
parent 07c934d2f9
commit ad1e9f78fc
2 changed files with 63 additions and 2 deletions

View file

@ -5,6 +5,7 @@ import constants from 'utils/strings/constants';
import { IoIosArrowForward, IoMdClose } from 'react-icons/io';
import FileUploadIcon from 'components/icons/FileUploadIcon';
import FolderUploadIcon from 'components/icons/FolderUploadIcon';
import { BsGoogle } from 'react-icons/bs';
export default function UploadTypeChoiceModal({
setElectronFiles,
@ -19,6 +20,7 @@ export default function UploadTypeChoiceModal({
const uploadFiles = async () => {
const files = await ImportService.showUploadFilesDialog();
hideFiletypeDialog();
ImportService.setSkipUpdatePendingUploads(false);
setIsUploadDirs(false);
setElectronFiles(files);
};
@ -26,10 +28,24 @@ export default function UploadTypeChoiceModal({
const uploadDirs = async () => {
const files = await ImportService.showUploadDirsDialog();
hideFiletypeDialog();
ImportService.setSkipUpdatePendingUploads(false);
setIsUploadDirs(true);
setElectronFiles(files);
};
const uploadGoogleTakeout = async () => {
const filePaths = await ImportService.showUploadZipDialog();
hideFiletypeDialog();
if (filePaths?.length > 0) {
const files = await ImportService.getElectronFilesFromGoogleZip(
filePaths[0]
);
ImportService.setSkipUpdatePendingUploads(true);
setIsUploadDirs(true);
setElectronFiles(files);
}
};
return (
<Modal
show={showUploadTypeChoiceModal}
@ -102,6 +118,32 @@ export default function UploadTypeChoiceModal({
</Container>
</Button>
</Row>
<Row className="justify-content-md-center py-2">
<Button
variant="light"
onClick={uploadGoogleTakeout}
style={{ width: '90%', height: '6vh' }}>
<Container>
<Row>
<div>
<BsGoogle
size={25}
style={{
marginRight: '0.2em',
marginLeft: '0.2em',
}}
/>
<b className="ml-2">
Upload Google Takeout
</b>
</div>
<div className="ml-auto d-flex align-items-center">
<IoIosArrowForward />
</div>
</Row>
</Container>
</Button>
</Row>
</Container>
</Modal.Body>
</Modal>

View file

@ -5,12 +5,25 @@ import { runningInBrowser } from 'utils/common';
class ImportService {
ElectronAPIs: any;
private allElectronAPIsExist: boolean = false;
private skipUpdatePendingUploads = false;
constructor() {
this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs'];
this.allElectronAPIsExist = !!this.ElectronAPIs?.exists;
}
setSkipUpdatePendingUploads(skip: boolean) {
this.skipUpdatePendingUploads = skip;
}
async getElectronFilesFromGoogleZip(
zipPath: string
): Promise<ElectronFile[]> {
if (this.allElectronAPIsExist) {
return this.ElectronAPIs.getElectronFilesFromGoogleZip(zipPath);
}
}
async showUploadFilesDialog(): Promise<string[]> {
if (this.allElectronAPIsExist) {
return this.ElectronAPIs.showUploadFilesDialog();
@ -23,6 +36,12 @@ class ImportService {
}
}
async showUploadZipDialog(): Promise<string[]> {
if (this.allElectronAPIsExist) {
return this.ElectronAPIs.showUploadZipDialog();
}
}
async getPendingUploads() {
if (this.allElectronAPIsExist) {
const { files, collectionName } =
@ -41,7 +60,7 @@ class ImportService {
files: FileWithCollection[],
collections: Collection[]
) {
if (this.allElectronAPIsExist) {
if (this.allElectronAPIsExist && !this.skipUpdatePendingUploads) {
let collectionName: string;
if (collections.length === 1) {
collectionName = collections[0].name;
@ -54,7 +73,7 @@ class ImportService {
}
updatePendingUploads(files: FileWithCollection[]) {
if (this.allElectronAPIsExist) {
if (this.allElectronAPIsExist && !this.skipUpdatePendingUploads) {
const filePaths = files.map(
(file) => (file.file as ElectronFile).path
);