|
@@ -10,7 +10,6 @@ import { SetCollections, SetCollectionSelectorAttributes } from 'types/gallery';
|
|
|
import { GalleryContext } from 'pages/gallery';
|
|
|
import { AppContext } from 'pages/_app';
|
|
|
import { logError } from 'utils/sentry';
|
|
|
-import UploadManager from 'services/upload/uploadManager';
|
|
|
import uploadManager from 'services/upload/uploadManager';
|
|
|
import ImportService from 'services/importService';
|
|
|
import isElectron from 'is-electron';
|
|
@@ -40,7 +39,10 @@ import {
|
|
|
PICKED_UPLOAD_TYPE,
|
|
|
} from 'constants/upload';
|
|
|
import importService from 'services/importService';
|
|
|
-import { getDownloadAppMessage } from 'utils/ui';
|
|
|
+import {
|
|
|
+ getDownloadAppMessage,
|
|
|
+ getRootLevelFileWithFolderNotAllowMessage,
|
|
|
+} from 'utils/ui';
|
|
|
import UploadTypeSelector from './UploadTypeSelector';
|
|
|
import {
|
|
|
filterOutSystemFiles,
|
|
@@ -49,21 +51,29 @@ import {
|
|
|
} from 'utils/upload';
|
|
|
import { getUserOwnedCollections } from 'utils/collection';
|
|
|
import billingService from 'services/billingService';
|
|
|
+import { addLogLine } from 'utils/logging';
|
|
|
+import { PublicCollectionGalleryContext } from 'utils/publicCollectionGallery';
|
|
|
+import UserNameInputDialog from 'components/UserNameInputDialog';
|
|
|
+import {
|
|
|
+ getPublicCollectionUID,
|
|
|
+ getPublicCollectionUploaderName,
|
|
|
+ savePublicCollectionUploaderName,
|
|
|
+} from 'services/publicCollectionService';
|
|
|
|
|
|
const FIRST_ALBUM_NAME = 'My First Album';
|
|
|
|
|
|
interface Props {
|
|
|
syncWithRemote: (force?: boolean, silent?: boolean) => Promise<void>;
|
|
|
- closeCollectionSelector: () => void;
|
|
|
+ closeCollectionSelector?: () => void;
|
|
|
closeUploadTypeSelector: () => void;
|
|
|
- setCollectionSelectorAttributes: SetCollectionSelectorAttributes;
|
|
|
- setCollectionNamerAttributes: SetCollectionNamerAttributes;
|
|
|
+ setCollectionSelectorAttributes?: SetCollectionSelectorAttributes;
|
|
|
+ setCollectionNamerAttributes?: SetCollectionNamerAttributes;
|
|
|
setLoading: SetLoading;
|
|
|
setShouldDisableDropzone: (value: boolean) => void;
|
|
|
- showCollectionSelector: () => void;
|
|
|
+ showCollectionSelector?: () => void;
|
|
|
setFiles: SetFiles;
|
|
|
- setCollections: SetCollections;
|
|
|
- isFirstUpload: boolean;
|
|
|
+ setCollections?: SetCollections;
|
|
|
+ isFirstUpload?: boolean;
|
|
|
uploadTypeSelectorView: boolean;
|
|
|
showSessionExpiredMessage: () => void;
|
|
|
showUploadFilesDialog: () => void;
|
|
@@ -71,9 +81,17 @@ interface Props {
|
|
|
webFolderSelectorFiles: File[];
|
|
|
webFileSelectorFiles: File[];
|
|
|
dragAndDropFiles: File[];
|
|
|
+ zipUploadDisabled?: boolean;
|
|
|
+ uploadCollection?: Collection;
|
|
|
}
|
|
|
|
|
|
export default function Uploader(props: Props) {
|
|
|
+ const appContext = useContext(AppContext);
|
|
|
+ const galleryContext = useContext(GalleryContext);
|
|
|
+ const publicCollectionGalleryContext = useContext(
|
|
|
+ PublicCollectionGalleryContext
|
|
|
+ );
|
|
|
+
|
|
|
const [uploadProgressView, setUploadProgressView] = useState(false);
|
|
|
const [uploadStage, setUploadStage] = useState<UPLOAD_STAGES>(
|
|
|
UPLOAD_STAGES.START
|
|
@@ -92,11 +110,13 @@ export default function Uploader(props: Props) {
|
|
|
const [hasLivePhotos, setHasLivePhotos] = useState(false);
|
|
|
|
|
|
const [choiceModalView, setChoiceModalView] = useState(false);
|
|
|
+ const [userNameInputDialogView, setUserNameInputDialogView] =
|
|
|
+ useState(false);
|
|
|
const [importSuggestion, setImportSuggestion] = useState<ImportSuggestion>(
|
|
|
DEFAULT_IMPORT_SUGGESTION
|
|
|
);
|
|
|
- const appContext = useContext(AppContext);
|
|
|
- const galleryContext = useContext(GalleryContext);
|
|
|
+ const [electronFiles, setElectronFiles] = useState<ElectronFile[]>(null);
|
|
|
+ const [webFiles, setWebFiles] = useState([]);
|
|
|
|
|
|
const toUploadFiles = useRef<File[] | ElectronFile[]>(null);
|
|
|
const isPendingDesktopUpload = useRef(false);
|
|
@@ -105,20 +125,33 @@ export default function Uploader(props: Props) {
|
|
|
const pickedUploadType = useRef<PICKED_UPLOAD_TYPE>(null);
|
|
|
const zipPaths = useRef<string[]>(null);
|
|
|
const currentUploadPromise = useRef<Promise<void>>(null);
|
|
|
- const [electronFiles, setElectronFiles] = useState<ElectronFile[]>(null);
|
|
|
- const [webFiles, setWebFiles] = useState([]);
|
|
|
+ const uploadRunning = useRef(false);
|
|
|
+ const uploaderNameRef = useRef<string>(null);
|
|
|
|
|
|
const closeUploadProgress = () => setUploadProgressView(false);
|
|
|
+ const showUserNameInputDialog = () => setUserNameInputDialogView(true);
|
|
|
|
|
|
const setCollectionName = (collectionName: string) => {
|
|
|
isPendingDesktopUpload.current = true;
|
|
|
pendingDesktopUploadCollectionName.current = collectionName;
|
|
|
};
|
|
|
|
|
|
- const uploadRunning = useRef(false);
|
|
|
+ const handleChoiceModalClose = () => {
|
|
|
+ setChoiceModalView(false);
|
|
|
+ uploadRunning.current = false;
|
|
|
+ };
|
|
|
+ const handleCollectionSelectorCancel = () => {
|
|
|
+ uploadRunning.current = false;
|
|
|
+ appContext.resetSharedFiles();
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleUserNameInputDialogClose = () => {
|
|
|
+ setUserNameInputDialogView(false);
|
|
|
+ uploadRunning.current = false;
|
|
|
+ };
|
|
|
|
|
|
useEffect(() => {
|
|
|
- UploadManager.init(
|
|
|
+ uploadManager.init(
|
|
|
{
|
|
|
setPercentComplete,
|
|
|
setUploadCounter,
|
|
@@ -128,12 +161,16 @@ export default function Uploader(props: Props) {
|
|
|
setUploadFilenames: setUploadFileNames,
|
|
|
setHasLivePhotos,
|
|
|
},
|
|
|
- props.setFiles
|
|
|
+ props.setFiles,
|
|
|
+ publicCollectionGalleryContext
|
|
|
);
|
|
|
|
|
|
if (isElectron() && ImportService.checkAllElectronAPIsExists()) {
|
|
|
ImportService.getPendingUploads().then(
|
|
|
({ files: electronFiles, collectionName, type }) => {
|
|
|
+ addLogLine(
|
|
|
+ `found pending desktop upload, resuming uploads`
|
|
|
+ );
|
|
|
resumeDesktopUpload(type, electronFiles, collectionName);
|
|
|
}
|
|
|
);
|
|
@@ -144,7 +181,11 @@ export default function Uploader(props: Props) {
|
|
|
appContext.setIsFolderSyncRunning
|
|
|
);
|
|
|
}
|
|
|
- }, []);
|
|
|
+ }, [
|
|
|
+ publicCollectionGalleryContext.accessedThroughSharedURL,
|
|
|
+ publicCollectionGalleryContext.token,
|
|
|
+ publicCollectionGalleryContext.passwordToken,
|
|
|
+ ]);
|
|
|
|
|
|
// this handles the change of selectorFiles changes on web when user selects
|
|
|
// files for upload through the opened file/folder selector or dragAndDrop them
|
|
@@ -159,13 +200,16 @@ export default function Uploader(props: Props) {
|
|
|
pickedUploadType.current === PICKED_UPLOAD_TYPE.FOLDERS &&
|
|
|
props.webFolderSelectorFiles?.length > 0
|
|
|
) {
|
|
|
+ addLogLine(`received folder upload request`);
|
|
|
setWebFiles(props.webFolderSelectorFiles);
|
|
|
} else if (
|
|
|
pickedUploadType.current === PICKED_UPLOAD_TYPE.FILES &&
|
|
|
props.webFileSelectorFiles?.length > 0
|
|
|
) {
|
|
|
+ addLogLine(`received file upload request`);
|
|
|
setWebFiles(props.webFileSelectorFiles);
|
|
|
} else if (props.dragAndDropFiles?.length > 0) {
|
|
|
+ addLogLine(`received drag and drop upload request`);
|
|
|
setWebFiles(props.dragAndDropFiles);
|
|
|
}
|
|
|
}, [
|
|
@@ -180,17 +224,37 @@ export default function Uploader(props: Props) {
|
|
|
webFiles?.length > 0 ||
|
|
|
appContext.sharedFiles?.length > 0
|
|
|
) {
|
|
|
+ addLogLine(
|
|
|
+ `upload request type:${
|
|
|
+ electronFiles?.length > 0
|
|
|
+ ? 'electronFiles'
|
|
|
+ : webFiles?.length > 0
|
|
|
+ ? 'webFiles'
|
|
|
+ : 'sharedFiles'
|
|
|
+ } count ${
|
|
|
+ electronFiles?.length ??
|
|
|
+ webFiles?.length ??
|
|
|
+ appContext?.sharedFiles.length
|
|
|
+ }`
|
|
|
+ );
|
|
|
if (uploadRunning.current) {
|
|
|
if (watchFolderService.isUploadRunning()) {
|
|
|
+ addLogLine(
|
|
|
+ 'watchFolder upload was running, pausing it to run user upload'
|
|
|
+ );
|
|
|
// pause watch folder service on user upload
|
|
|
watchFolderService.pauseRunningSync();
|
|
|
} else {
|
|
|
+ addLogLine(
|
|
|
+ 'an upload is already running, rejecting new upload request'
|
|
|
+ );
|
|
|
// no-op
|
|
|
// a user upload is already in progress
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
if (isCanvasBlocked()) {
|
|
|
+ addLogLine('canvas blocked, blocking upload');
|
|
|
appContext.setDialogMessage({
|
|
|
title: constants.CANVAS_BLOCKED_TITLE,
|
|
|
|
|
@@ -235,7 +299,8 @@ export default function Uploader(props: Props) {
|
|
|
handleCollectionCreationAndUpload(
|
|
|
importSuggestion,
|
|
|
props.isFirstUpload,
|
|
|
- pickedUploadType.current
|
|
|
+ pickedUploadType.current,
|
|
|
+ publicCollectionGalleryContext.accessedThroughSharedURL
|
|
|
);
|
|
|
pickedUploadType.current = null;
|
|
|
props.setLoading(false);
|
|
@@ -256,14 +321,20 @@ export default function Uploader(props: Props) {
|
|
|
};
|
|
|
|
|
|
const preCollectionCreationAction = async () => {
|
|
|
- props.closeCollectionSelector();
|
|
|
+ props.closeCollectionSelector?.();
|
|
|
props.setShouldDisableDropzone(!uploadManager.shouldAllowNewUpload());
|
|
|
setUploadStage(UPLOAD_STAGES.START);
|
|
|
setUploadProgressView(true);
|
|
|
};
|
|
|
|
|
|
- const uploadFilesToExistingCollection = async (collection: Collection) => {
|
|
|
+ const uploadFilesToExistingCollection = async (
|
|
|
+ collection: Collection,
|
|
|
+ uploaderName?: string
|
|
|
+ ) => {
|
|
|
try {
|
|
|
+ addLogLine(
|
|
|
+ `upload file to an existing collection - "${collection.name}"`
|
|
|
+ );
|
|
|
await preCollectionCreationAction();
|
|
|
const filesWithCollectionToUpload: FileWithCollection[] =
|
|
|
toUploadFiles.current.map((file, index) => ({
|
|
@@ -271,10 +342,11 @@ export default function Uploader(props: Props) {
|
|
|
localID: index,
|
|
|
collectionID: collection.id,
|
|
|
}));
|
|
|
- waitInQueueAndUploadFiles(filesWithCollectionToUpload, [
|
|
|
- collection,
|
|
|
- ]);
|
|
|
- toUploadFiles.current = null;
|
|
|
+ waitInQueueAndUploadFiles(
|
|
|
+ filesWithCollectionToUpload,
|
|
|
+ [collection],
|
|
|
+ uploaderName
|
|
|
+ );
|
|
|
} catch (e) {
|
|
|
logError(e, 'Failed to upload files to existing collections');
|
|
|
}
|
|
@@ -285,8 +357,11 @@ export default function Uploader(props: Props) {
|
|
|
collectionName?: string
|
|
|
) => {
|
|
|
try {
|
|
|
+ addLogLine(
|
|
|
+ `upload file to an new collections strategy:${strategy} ,collectionName:${collectionName}`
|
|
|
+ );
|
|
|
await preCollectionCreationAction();
|
|
|
- const filesWithCollectionToUpload: FileWithCollection[] = [];
|
|
|
+ let filesWithCollectionToUpload: FileWithCollection[] = [];
|
|
|
const collections: Collection[] = [];
|
|
|
let collectionNameToFilesMap = new Map<
|
|
|
string,
|
|
@@ -302,6 +377,9 @@ export default function Uploader(props: Props) {
|
|
|
toUploadFiles.current
|
|
|
);
|
|
|
}
|
|
|
+ addLogLine(
|
|
|
+ `upload collections - [${[...collectionNameToFilesMap.keys()]}]`
|
|
|
+ );
|
|
|
try {
|
|
|
const existingCollection = getUserOwnedCollections(
|
|
|
await syncCollections()
|
|
@@ -320,13 +398,14 @@ export default function Uploader(props: Props) {
|
|
|
...existingCollection,
|
|
|
...collections,
|
|
|
]);
|
|
|
- filesWithCollectionToUpload.push(
|
|
|
+ filesWithCollectionToUpload = [
|
|
|
+ ...filesWithCollectionToUpload,
|
|
|
...files.map((file) => ({
|
|
|
localID: index++,
|
|
|
collectionID: collection.id,
|
|
|
file,
|
|
|
- }))
|
|
|
- );
|
|
|
+ })),
|
|
|
+ ];
|
|
|
}
|
|
|
} catch (e) {
|
|
|
closeUploadProgress();
|
|
@@ -348,13 +427,18 @@ export default function Uploader(props: Props) {
|
|
|
|
|
|
const waitInQueueAndUploadFiles = (
|
|
|
filesWithCollectionToUploadIn: FileWithCollection[],
|
|
|
- collections: Collection[]
|
|
|
+ collections: Collection[],
|
|
|
+ uploaderName?: string
|
|
|
) => {
|
|
|
const currentPromise = currentUploadPromise.current;
|
|
|
currentUploadPromise.current = waitAndRun(
|
|
|
currentPromise,
|
|
|
async () =>
|
|
|
- await uploadFiles(filesWithCollectionToUploadIn, collections)
|
|
|
+ await uploadFiles(
|
|
|
+ filesWithCollectionToUploadIn,
|
|
|
+ collections,
|
|
|
+ uploaderName
|
|
|
+ )
|
|
|
);
|
|
|
};
|
|
|
|
|
@@ -372,9 +456,11 @@ export default function Uploader(props: Props) {
|
|
|
|
|
|
const uploadFiles = async (
|
|
|
filesWithCollectionToUploadIn: FileWithCollection[],
|
|
|
- collections: Collection[]
|
|
|
+ collections: Collection[],
|
|
|
+ uploaderName?: string
|
|
|
) => {
|
|
|
try {
|
|
|
+ addLogLine('uploadFiles called');
|
|
|
preUploadAction();
|
|
|
if (
|
|
|
isElectron() &&
|
|
@@ -399,7 +485,8 @@ export default function Uploader(props: Props) {
|
|
|
const shouldCloseUploadProgress =
|
|
|
await uploadManager.queueFilesForUpload(
|
|
|
filesWithCollectionToUploadIn,
|
|
|
- collections
|
|
|
+ collections,
|
|
|
+ uploaderName
|
|
|
);
|
|
|
if (shouldCloseUploadProgress) {
|
|
|
closeUploadProgress();
|
|
@@ -416,6 +503,7 @@ export default function Uploader(props: Props) {
|
|
|
}
|
|
|
}
|
|
|
} catch (err) {
|
|
|
+ logError(err, 'failed to upload files');
|
|
|
showUserFacingError(err.message);
|
|
|
closeUploadProgress();
|
|
|
throw err;
|
|
@@ -426,14 +514,18 @@ export default function Uploader(props: Props) {
|
|
|
|
|
|
const retryFailed = async () => {
|
|
|
try {
|
|
|
+ addLogLine('user retrying failed upload');
|
|
|
const filesWithCollections =
|
|
|
- await uploadManager.getFailedFilesWithCollections();
|
|
|
+ uploadManager.getFailedFilesWithCollections();
|
|
|
+ const uploaderName = uploadManager.getUploaderName();
|
|
|
await preUploadAction();
|
|
|
await uploadManager.queueFilesForUpload(
|
|
|
filesWithCollections.files,
|
|
|
- filesWithCollections.collections
|
|
|
+ filesWithCollections.collections,
|
|
|
+ uploaderName
|
|
|
);
|
|
|
} catch (err) {
|
|
|
+ logError(err, 'retry failed files failed');
|
|
|
showUserFacingError(err.message);
|
|
|
closeUploadProgress();
|
|
|
} finally {
|
|
@@ -449,35 +541,33 @@ export default function Uploader(props: Props) {
|
|
|
case CustomError.SUBSCRIPTION_EXPIRED:
|
|
|
notification = {
|
|
|
variant: 'danger',
|
|
|
- message: constants.SUBSCRIPTION_EXPIRED,
|
|
|
- action: {
|
|
|
- text: constants.RENEW_NOW,
|
|
|
- callback: billingService.redirectToCustomerPortal,
|
|
|
- },
|
|
|
+ subtext: constants.SUBSCRIPTION_EXPIRED,
|
|
|
+ message: constants.RENEW_NOW,
|
|
|
+ onClick: () => billingService.redirectToCustomerPortal(),
|
|
|
};
|
|
|
break;
|
|
|
case CustomError.STORAGE_QUOTA_EXCEEDED:
|
|
|
notification = {
|
|
|
variant: 'danger',
|
|
|
- message: constants.STORAGE_QUOTA_EXCEEDED,
|
|
|
- action: {
|
|
|
- text: constants.UPGRADE_NOW,
|
|
|
- callback: galleryContext.showPlanSelectorModal,
|
|
|
- },
|
|
|
- icon: <DiscFullIcon fontSize="large" />,
|
|
|
+ subtext: constants.STORAGE_QUOTA_EXCEEDED,
|
|
|
+ message: constants.UPGRADE_NOW,
|
|
|
+ onClick: () => galleryContext.showPlanSelectorModal(),
|
|
|
+ startIcon: <DiscFullIcon />,
|
|
|
};
|
|
|
break;
|
|
|
default:
|
|
|
notification = {
|
|
|
variant: 'danger',
|
|
|
message: constants.UNKNOWN_ERROR,
|
|
|
+ onClick: () => null,
|
|
|
};
|
|
|
}
|
|
|
- galleryContext.setNotificationAttributes(notification);
|
|
|
+ appContext.setNotificationAttributes(notification);
|
|
|
}
|
|
|
|
|
|
const uploadToSingleNewCollection = (collectionName: string) => {
|
|
|
if (collectionName) {
|
|
|
+ addLogLine(`upload to single collection - "${collectionName}"`);
|
|
|
uploadFilesToNewCollections(
|
|
|
UPLOAD_STRATEGY.SINGLE_COLLECTION,
|
|
|
collectionName
|
|
@@ -495,45 +585,75 @@ export default function Uploader(props: Props) {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- const handleCollectionCreationAndUpload = (
|
|
|
+ const handleCollectionCreationAndUpload = async (
|
|
|
importSuggestion: ImportSuggestion,
|
|
|
isFirstUpload: boolean,
|
|
|
- pickedUploadType: PICKED_UPLOAD_TYPE
|
|
|
+ pickedUploadType: PICKED_UPLOAD_TYPE,
|
|
|
+ accessedThroughSharedURL?: boolean
|
|
|
) => {
|
|
|
- if (isPendingDesktopUpload.current) {
|
|
|
- isPendingDesktopUpload.current = false;
|
|
|
- if (pendingDesktopUploadCollectionName.current) {
|
|
|
- uploadToSingleNewCollection(
|
|
|
- pendingDesktopUploadCollectionName.current
|
|
|
+ try {
|
|
|
+ if (accessedThroughSharedURL) {
|
|
|
+ addLogLine(
|
|
|
+ `uploading files to pulbic collection - ${props.uploadCollection.name} - ${props.uploadCollection.id}`
|
|
|
);
|
|
|
- pendingDesktopUploadCollectionName.current = null;
|
|
|
- } else {
|
|
|
+ const uploaderName = await getPublicCollectionUploaderName(
|
|
|
+ getPublicCollectionUID(publicCollectionGalleryContext.token)
|
|
|
+ );
|
|
|
+ uploaderNameRef.current = uploaderName;
|
|
|
+ showUserNameInputDialog();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isPendingDesktopUpload.current) {
|
|
|
+ isPendingDesktopUpload.current = false;
|
|
|
+ if (pendingDesktopUploadCollectionName.current) {
|
|
|
+ addLogLine(
|
|
|
+ `upload pending files to collection - ${pendingDesktopUploadCollectionName.current}`
|
|
|
+ );
|
|
|
+ uploadToSingleNewCollection(
|
|
|
+ pendingDesktopUploadCollectionName.current
|
|
|
+ );
|
|
|
+ pendingDesktopUploadCollectionName.current = null;
|
|
|
+ } else {
|
|
|
+ addLogLine(
|
|
|
+ `pending upload - strategy - "multiple collections" `
|
|
|
+ );
|
|
|
+ uploadFilesToNewCollections(
|
|
|
+ UPLOAD_STRATEGY.COLLECTION_PER_FOLDER
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (isElectron() && pickedUploadType === PICKED_UPLOAD_TYPE.ZIPS) {
|
|
|
+ addLogLine('uploading zip files');
|
|
|
uploadFilesToNewCollections(
|
|
|
UPLOAD_STRATEGY.COLLECTION_PER_FOLDER
|
|
|
);
|
|
|
+ return;
|
|
|
}
|
|
|
- return;
|
|
|
- }
|
|
|
- if (isElectron() && pickedUploadType === PICKED_UPLOAD_TYPE.ZIPS) {
|
|
|
- uploadFilesToNewCollections(UPLOAD_STRATEGY.COLLECTION_PER_FOLDER);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (isFirstUpload && !importSuggestion.rootFolderName) {
|
|
|
- importSuggestion.rootFolderName = FIRST_ALBUM_NAME;
|
|
|
- }
|
|
|
- let showNextModal = () => {};
|
|
|
- if (importSuggestion.hasNestedFolders) {
|
|
|
- showNextModal = () => setChoiceModalView(true);
|
|
|
- } else {
|
|
|
- showNextModal = () =>
|
|
|
- uploadToSingleNewCollection(importSuggestion.rootFolderName);
|
|
|
+ if (isFirstUpload && !importSuggestion.rootFolderName) {
|
|
|
+ importSuggestion.rootFolderName = FIRST_ALBUM_NAME;
|
|
|
+ }
|
|
|
+ let showNextModal = () => {};
|
|
|
+ if (importSuggestion.hasNestedFolders) {
|
|
|
+ addLogLine(`nested folders detected`);
|
|
|
+ showNextModal = () => setChoiceModalView(true);
|
|
|
+ } else {
|
|
|
+ showNextModal = () =>
|
|
|
+ uploadToSingleNewCollection(
|
|
|
+ importSuggestion.rootFolderName
|
|
|
+ );
|
|
|
+ }
|
|
|
+ props.setCollectionSelectorAttributes({
|
|
|
+ callback: uploadFilesToExistingCollection,
|
|
|
+ onCancel: handleCollectionSelectorCancel,
|
|
|
+ showNextModal,
|
|
|
+ title: constants.UPLOAD_TO_COLLECTION,
|
|
|
+ });
|
|
|
+ } catch (e) {
|
|
|
+ logError(e, 'handleCollectionCreationAndUpload failed');
|
|
|
}
|
|
|
- props.setCollectionSelectorAttributes({
|
|
|
- callback: uploadFilesToExistingCollection,
|
|
|
- showNextModal,
|
|
|
- title: constants.UPLOAD_TO_COLLECTION,
|
|
|
- });
|
|
|
};
|
|
|
+
|
|
|
const handleDesktopUpload = async (type: PICKED_UPLOAD_TYPE) => {
|
|
|
let files: ElectronFile[];
|
|
|
pickedUploadType.current = type;
|
|
@@ -547,6 +667,9 @@ export default function Uploader(props: Props) {
|
|
|
zipPaths.current = response.zipPaths;
|
|
|
}
|
|
|
if (files?.length > 0) {
|
|
|
+ addLogLine(
|
|
|
+ ` desktop upload for type:${type} and fileCount: ${files?.length} requested`
|
|
|
+ );
|
|
|
setElectronFiles(files);
|
|
|
props.closeUploadTypeSelector();
|
|
|
}
|
|
@@ -579,26 +702,57 @@ export default function Uploader(props: Props) {
|
|
|
const handleFolderUpload = handleUpload(PICKED_UPLOAD_TYPE.FOLDERS);
|
|
|
const handleZipUpload = handleUpload(PICKED_UPLOAD_TYPE.ZIPS);
|
|
|
|
|
|
+ const handlePublicUpload = async (
|
|
|
+ uploaderName: string,
|
|
|
+ skipSave?: boolean
|
|
|
+ ) => {
|
|
|
+ try {
|
|
|
+ if (!skipSave) {
|
|
|
+ savePublicCollectionUploaderName(
|
|
|
+ getPublicCollectionUID(
|
|
|
+ publicCollectionGalleryContext.token
|
|
|
+ ),
|
|
|
+ uploaderName
|
|
|
+ );
|
|
|
+ }
|
|
|
+ await uploadFilesToExistingCollection(
|
|
|
+ props.uploadCollection,
|
|
|
+ uploaderName
|
|
|
+ );
|
|
|
+ } catch (e) {
|
|
|
+ logError(e, 'public upload failed ');
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleUploadToSingleCollection = () => {
|
|
|
+ uploadToSingleNewCollection(importSuggestion.rootFolderName);
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleUploadToMultipleCollections = () => {
|
|
|
+ if (importSuggestion.hasRootLevelFileWithFolder) {
|
|
|
+ appContext.setDialogMessage(
|
|
|
+ getRootLevelFileWithFolderNotAllowMessage()
|
|
|
+ );
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ uploadFilesToNewCollections(UPLOAD_STRATEGY.COLLECTION_PER_FOLDER);
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<UploadStrategyChoiceModal
|
|
|
open={choiceModalView}
|
|
|
- onClose={() => setChoiceModalView(false)}
|
|
|
- uploadToSingleCollection={() =>
|
|
|
- uploadToSingleNewCollection(importSuggestion.rootFolderName)
|
|
|
- }
|
|
|
- uploadToMultipleCollection={() =>
|
|
|
- uploadFilesToNewCollections(
|
|
|
- UPLOAD_STRATEGY.COLLECTION_PER_FOLDER
|
|
|
- )
|
|
|
- }
|
|
|
+ onClose={handleChoiceModalClose}
|
|
|
+ uploadToSingleCollection={handleUploadToSingleCollection}
|
|
|
+ uploadToMultipleCollection={handleUploadToMultipleCollections}
|
|
|
/>
|
|
|
<UploadTypeSelector
|
|
|
show={props.uploadTypeSelectorView}
|
|
|
- onHide={props.closeUploadTypeSelector}
|
|
|
+ onClose={props.closeUploadTypeSelector}
|
|
|
uploadFiles={handleFileUpload}
|
|
|
uploadFolders={handleFolderUpload}
|
|
|
uploadGoogleTakeoutZips={handleZipUpload}
|
|
|
+ hideZipUploadOption={props.zipUploadDisabled}
|
|
|
/>
|
|
|
<UploadProgress
|
|
|
open={uploadProgressView}
|
|
@@ -613,6 +767,13 @@ export default function Uploader(props: Props) {
|
|
|
finishedUploads={finishedUploads}
|
|
|
cancelUploads={cancelUploads}
|
|
|
/>
|
|
|
+ <UserNameInputDialog
|
|
|
+ open={userNameInputDialogView}
|
|
|
+ onClose={handleUserNameInputDialogClose}
|
|
|
+ onNameSubmit={handlePublicUpload}
|
|
|
+ toUploadFilesCount={toUploadFiles.current?.length}
|
|
|
+ uploaderName={uploaderNameRef.current}
|
|
|
+ />
|
|
|
</>
|
|
|
);
|
|
|
}
|