-
Notifications
You must be signed in to change notification settings - Fork 25
feat: preserve empty folders on upload #1018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9ad5986
feat: preserve empty folders on upload via drag&drop
JammingBen b4fe148
fix: make folders in upload overlay clickable again
JammingBen 8f7b30c
feat: only count root level items in upload overlay
JammingBen 9343226
feat: preserve empty folders on upload via button
JammingBen 9eaafb3
fix: empty folder handling on public drop pages
JammingBen b736178
refactor: simplify empty folder retrieval on drop
JammingBen 7d0fffa
test: add unit tests for empty folder uploads
JammingBen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { urlJoin } from '@opencloud-eu/web-client' | ||
| import { createFolderDummyFile } from '@opencloud-eu/web-pkg' | ||
|
|
||
| /** | ||
| * This method uses the Directory API to retrieve items from a directory | ||
| * that the user selects from their file system for upload. | ||
| * It returns an array of File objects, including dummy files for empty folders. | ||
| * | ||
| * See https://developer.mozilla.org/en-US/docs/Web/API/Window/showDirectoryPicker | ||
| */ | ||
| export const getItemsViaDirectoryPicker = async ( | ||
| onError?: (error?: unknown) => void | ||
| ): Promise<File[]> => { | ||
| const dirHandle: FileSystemDirectoryHandle = await (window as any).showDirectoryPicker() | ||
|
|
||
| async function* getItemsFromDirectory( | ||
| dirHandle: FileSystemDirectoryHandle, | ||
| path: string | ||
| ): AsyncGenerator<File> { | ||
| let hasFiles = false | ||
|
|
||
| for await (const [name, handle] of (dirHandle as any).entries()) { | ||
| if (handle.kind === 'directory') { | ||
| // recurse into the directory | ||
| yield* getItemsFromDirectory(handle, urlJoin(path, name)) | ||
| } else { | ||
| hasFiles = true | ||
| try { | ||
| const file = await handle.getFile() | ||
| ;(file as any).relativePath = urlJoin(path, name, { leadingSlash: true }) | ||
| yield file | ||
| } catch (error) { | ||
| console.log(error) | ||
| onError?.(error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!hasFiles) { | ||
| // empty folder, create a dummy file to represent it in the Uppy queue. | ||
| // note that a folder that only contains other folders is always considered empty, | ||
| // even if there are files located further down the hierarchy. this is because we don't | ||
| // have insight into the contents of the subfolders at this point. | ||
| yield createFolderDummyFile(path) | ||
| } | ||
| } | ||
|
|
||
| const items: File[] = [] | ||
| for await (const item of getItemsFromDirectory(dirHandle, dirHandle.name)) { | ||
| items.push(item) | ||
| } | ||
|
|
||
| return items | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.