wip zip selection on web itself
This commit is contained in:
parent
a3d06c54af
commit
13f0ff3af5
5 changed files with 85 additions and 10 deletions
|
@ -76,8 +76,10 @@ interface Props {
|
||||||
showSessionExpiredMessage: () => void;
|
showSessionExpiredMessage: () => void;
|
||||||
showUploadFilesDialog: () => void;
|
showUploadFilesDialog: () => void;
|
||||||
showUploadDirsDialog: () => void;
|
showUploadDirsDialog: () => void;
|
||||||
|
showUploadZipFilesDialog?: () => void;
|
||||||
webFolderSelectorFiles: File[];
|
webFolderSelectorFiles: File[];
|
||||||
webFileSelectorFiles: File[];
|
webFileSelectorFiles: File[];
|
||||||
|
webFileSelectorZipFiles?: File[];
|
||||||
dragAndDropFiles: File[];
|
dragAndDropFiles: File[];
|
||||||
uploadCollection?: Collection;
|
uploadCollection?: Collection;
|
||||||
uploadTypeSelectorIntent: UploadTypeSelectorIntent;
|
uploadTypeSelectorIntent: UploadTypeSelectorIntent;
|
||||||
|
@ -255,24 +257,59 @@ export default function Uploader(props: Props) {
|
||||||
) {
|
) {
|
||||||
log.info(`received file upload request`);
|
log.info(`received file upload request`);
|
||||||
setWebFiles(props.webFileSelectorFiles);
|
setWebFiles(props.webFileSelectorFiles);
|
||||||
|
} else if (
|
||||||
|
pickedUploadType.current === PICKED_UPLOAD_TYPE.ZIPS &&
|
||||||
|
props.webFileSelectorZipFiles?.length > 0
|
||||||
|
) {
|
||||||
|
if (electron) {
|
||||||
|
const main = async () => {
|
||||||
|
const zips: File[] = [];
|
||||||
|
let electronFiles = [] as ElectronFile[];
|
||||||
|
for (const file of props.webFileSelectorZipFiles) {
|
||||||
|
if (file.name.endsWith(".zip")) {
|
||||||
|
const zipFiles = await electron.lsZip(
|
||||||
|
(file as any).path,
|
||||||
|
);
|
||||||
|
log.info(
|
||||||
|
`zip file - ${file.name} contains ${zipFiles.length} files`,
|
||||||
|
);
|
||||||
|
zips.push(file);
|
||||||
|
// TODO(MR): This cast is incorrect, but interim.
|
||||||
|
electronFiles = [
|
||||||
|
...electronFiles,
|
||||||
|
...(zipFiles as unknown as ElectronFile[]),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// setWebFiles(props.webFileSelectorZipFiles);
|
||||||
|
zipPaths.current = zips.map((file) => (file as any).path);
|
||||||
|
setElectronFiles(electronFiles);
|
||||||
|
};
|
||||||
|
main();
|
||||||
|
}
|
||||||
} else if (props.dragAndDropFiles?.length > 0) {
|
} else if (props.dragAndDropFiles?.length > 0) {
|
||||||
isDragAndDrop.current = true;
|
isDragAndDrop.current = true;
|
||||||
if (electron) {
|
if (electron) {
|
||||||
const main = async () => {
|
const main = async () => {
|
||||||
try {
|
try {
|
||||||
log.info(`uploading dropped files from desktop app`);
|
|
||||||
// check and parse dropped files which are zip files
|
// check and parse dropped files which are zip files
|
||||||
|
log.info(`uploading dropped files from desktop app`);
|
||||||
|
const zips: File[] = [];
|
||||||
let electronFiles = [] as ElectronFile[];
|
let electronFiles = [] as ElectronFile[];
|
||||||
for (const file of props.dragAndDropFiles) {
|
for (const file of props.dragAndDropFiles) {
|
||||||
if (file.name.endsWith(".zip")) {
|
if (file.name.endsWith(".zip")) {
|
||||||
const zipFiles =
|
const zipFiles = await electron.lsZip(
|
||||||
await electron.getElectronFilesFromGoogleZip(
|
(file as any).path,
|
||||||
(file as any).path,
|
);
|
||||||
);
|
|
||||||
log.info(
|
log.info(
|
||||||
`zip file - ${file.name} contains ${zipFiles.length} files`,
|
`zip file - ${file.name} contains ${zipFiles.length} files`,
|
||||||
);
|
);
|
||||||
electronFiles = [...electronFiles, ...zipFiles];
|
zips.push(file);
|
||||||
|
// TODO(MR): This cast is incorrect, but interim.
|
||||||
|
electronFiles = [
|
||||||
|
...electronFiles,
|
||||||
|
...(zipFiles as unknown as ElectronFile[]),
|
||||||
|
];
|
||||||
} else {
|
} else {
|
||||||
// type cast to ElectronFile as the file is dropped from desktop app
|
// type cast to ElectronFile as the file is dropped from desktop app
|
||||||
// type file and ElectronFile should be interchangeable, but currently they have some differences.
|
// type file and ElectronFile should be interchangeable, but currently they have some differences.
|
||||||
|
@ -290,6 +327,9 @@ export default function Uploader(props: Props) {
|
||||||
log.info(
|
log.info(
|
||||||
`uploading dropped files from desktop app - ${electronFiles.length} files found`,
|
`uploading dropped files from desktop app - ${electronFiles.length} files found`,
|
||||||
);
|
);
|
||||||
|
zipPaths.current = zips.map(
|
||||||
|
(file) => (file as any).path,
|
||||||
|
);
|
||||||
setElectronFiles(electronFiles);
|
setElectronFiles(electronFiles);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.error("failed to upload desktop dropped files", e);
|
log.error("failed to upload desktop dropped files", e);
|
||||||
|
@ -306,6 +346,7 @@ export default function Uploader(props: Props) {
|
||||||
props.dragAndDropFiles,
|
props.dragAndDropFiles,
|
||||||
props.webFileSelectorFiles,
|
props.webFileSelectorFiles,
|
||||||
props.webFolderSelectorFiles,
|
props.webFolderSelectorFiles,
|
||||||
|
props.webFileSelectorZipFiles,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -768,7 +809,11 @@ export default function Uploader(props: Props) {
|
||||||
} else if (type === PICKED_UPLOAD_TYPE.FOLDERS) {
|
} else if (type === PICKED_UPLOAD_TYPE.FOLDERS) {
|
||||||
props.showUploadDirsDialog();
|
props.showUploadDirsDialog();
|
||||||
} else {
|
} else {
|
||||||
appContext.setDialogMessage(getDownloadAppMessage());
|
if (props.showUploadZipFilesDialog && electron) {
|
||||||
|
props.showUploadZipFilesDialog();
|
||||||
|
} else {
|
||||||
|
appContext.setDialogMessage(getDownloadAppMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,16 @@ export default function UploadSelectorInputs({
|
||||||
getDragAndDropInputProps,
|
getDragAndDropInputProps,
|
||||||
getFileSelectorInputProps,
|
getFileSelectorInputProps,
|
||||||
getFolderSelectorInputProps,
|
getFolderSelectorInputProps,
|
||||||
|
getZipFileSelectorInputProps,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<input {...getDragAndDropInputProps()} />
|
<input {...getDragAndDropInputProps()} />
|
||||||
<input {...getFileSelectorInputProps()} />
|
<input {...getFileSelectorInputProps()} />
|
||||||
<input {...getFolderSelectorInputProps()} />
|
<input {...getFolderSelectorInputProps()} />
|
||||||
|
{getZipFileSelectorInputProps && (
|
||||||
|
<input {...getZipFileSelectorInputProps()} />
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,6 +224,14 @@ export default function Gallery() {
|
||||||
} = useFileInput({
|
} = useFileInput({
|
||||||
directory: true,
|
directory: true,
|
||||||
});
|
});
|
||||||
|
const {
|
||||||
|
selectedFiles: webFileSelectorZipFiles,
|
||||||
|
open: openZipFileSelector,
|
||||||
|
getInputProps: getZipFileSelectorInputProps,
|
||||||
|
} = useFileInput({
|
||||||
|
directory: false,
|
||||||
|
accept: ".zip"
|
||||||
|
});
|
||||||
|
|
||||||
const [isInSearchMode, setIsInSearchMode] = useState(false);
|
const [isInSearchMode, setIsInSearchMode] = useState(false);
|
||||||
const [searchResultSummary, setSetSearchResultSummary] =
|
const [searchResultSummary, setSetSearchResultSummary] =
|
||||||
|
@ -1023,6 +1031,7 @@ export default function Gallery() {
|
||||||
getDragAndDropInputProps={getDragAndDropInputProps}
|
getDragAndDropInputProps={getDragAndDropInputProps}
|
||||||
getFileSelectorInputProps={getFileSelectorInputProps}
|
getFileSelectorInputProps={getFileSelectorInputProps}
|
||||||
getFolderSelectorInputProps={getFolderSelectorInputProps}
|
getFolderSelectorInputProps={getFolderSelectorInputProps}
|
||||||
|
getZipFileSelectorInputProps={getZipFileSelectorInputProps}
|
||||||
/>
|
/>
|
||||||
{blockingLoad && (
|
{blockingLoad && (
|
||||||
<LoadingOverlay>
|
<LoadingOverlay>
|
||||||
|
@ -1123,10 +1132,12 @@ export default function Gallery() {
|
||||||
}
|
}
|
||||||
webFileSelectorFiles={webFileSelectorFiles}
|
webFileSelectorFiles={webFileSelectorFiles}
|
||||||
webFolderSelectorFiles={webFolderSelectorFiles}
|
webFolderSelectorFiles={webFolderSelectorFiles}
|
||||||
|
webFileSelectorZipFiles={webFileSelectorZipFiles}
|
||||||
dragAndDropFiles={dragAndDropFiles}
|
dragAndDropFiles={dragAndDropFiles}
|
||||||
uploadTypeSelectorView={uploadTypeSelectorView}
|
uploadTypeSelectorView={uploadTypeSelectorView}
|
||||||
showUploadFilesDialog={openFileSelector}
|
showUploadFilesDialog={openFileSelector}
|
||||||
showUploadDirsDialog={openFolderSelector}
|
showUploadDirsDialog={openFolderSelector}
|
||||||
|
showUploadZipFilesDialog={openZipFileSelector}
|
||||||
showSessionExpiredMessage={showSessionExpiredMessage}
|
showSessionExpiredMessage={showSessionExpiredMessage}
|
||||||
/>
|
/>
|
||||||
<Sidebar
|
<Sidebar
|
||||||
|
|
|
@ -550,6 +550,7 @@ export default function PublicCollectionGallery() {
|
||||||
getDragAndDropInputProps={getDragAndDropInputProps}
|
getDragAndDropInputProps={getDragAndDropInputProps}
|
||||||
getFileSelectorInputProps={getFileSelectorInputProps}
|
getFileSelectorInputProps={getFileSelectorInputProps}
|
||||||
getFolderSelectorInputProps={getFolderSelectorInputProps}
|
getFolderSelectorInputProps={getFolderSelectorInputProps}
|
||||||
|
getZipFileSelectorInputProps={undefined}
|
||||||
/>
|
/>
|
||||||
<SharedAlbumNavbar
|
<SharedAlbumNavbar
|
||||||
showUploadButton={
|
showUploadButton={
|
||||||
|
|
|
@ -18,6 +18,11 @@ export interface FileWithPath extends File {
|
||||||
readonly path?: string;
|
readonly path?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface UseFileInputParams {
|
||||||
|
directory?: boolean;
|
||||||
|
accept?: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return three things:
|
* Return three things:
|
||||||
*
|
*
|
||||||
|
@ -33,10 +38,18 @@ export interface FileWithPath extends File {
|
||||||
* user selected directories - in that case, it will be the recursive list of
|
* user selected directories - in that case, it will be the recursive list of
|
||||||
* files within this directory.
|
* files within this directory.
|
||||||
*
|
*
|
||||||
* @param param0 If {@link directory} is true, the file open dialog will ask the
|
* @param param0
|
||||||
* user to select directories. Otherwise it'll ask the user to select files.
|
*
|
||||||
|
* - If {@link directory} is true, the file open dialog will ask the user to
|
||||||
|
* select directories. Otherwise it'll ask the user to select files.
|
||||||
|
*
|
||||||
|
* - If {@link accept} is specified, it'll restrict the type of files that the
|
||||||
|
* user can select by setting the "accept" attribute of the underlying HTML
|
||||||
|
* input element we use to surface the file selector dialog. For value of
|
||||||
|
* accept can be an extension or a MIME type (See
|
||||||
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept).
|
||||||
*/
|
*/
|
||||||
export default function useFileInput({ directory }: { directory?: boolean }) {
|
export default function useFileInput({ directory, accept }: UseFileInputParams) {
|
||||||
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
const [selectedFiles, setSelectedFiles] = useState<File[]>([]);
|
||||||
const inputRef = useRef<HTMLInputElement>();
|
const inputRef = useRef<HTMLInputElement>();
|
||||||
|
|
||||||
|
@ -66,6 +79,7 @@ export default function useFileInput({ directory }: { directory?: boolean }) {
|
||||||
...(directory ? { directory: "", webkitdirectory: "" } : {}),
|
...(directory ? { directory: "", webkitdirectory: "" } : {}),
|
||||||
ref: inputRef,
|
ref: inputRef,
|
||||||
onChange: handleChange,
|
onChange: handleChange,
|
||||||
|
...(accept ? { accept } : {}),
|
||||||
}),
|
}),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue