-
-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Always populate relativePath for access across browser and electron #70
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
feat: Always populate relativePath for access across browser and electron #70
Conversation
| return fromDirEntry(entry) as any; | ||
| } | ||
|
|
||
| return fromDataTransferItem(item); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rolandjitsu I changed this to still call fromDataTransferItem while still getting the functionality I need.
…dd functionality to fromDataTransferItem instead.
|
@rolandjitsu Could you please review this again. I made the necessary changes. |
rolandjitsu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saul-prepared thanks for your contribution and sorry for the delayed reply. There are a few more changes needed that I hope make sense to you.
| Object.defineProperty(f, 'relativePath', { | ||
| value: typeof path === 'string' | ||
| ? path | ||
| // If <input webkitdirectory> is set, | ||
| // the File will have a {webkitRelativePath} property | ||
| // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory | ||
| : typeof webkitRelativePath === 'string' && webkitRelativePath.length > 0 | ||
| ? webkitRelativePath | ||
| : `/${file.name}`, // prepend forward slash (/) to ensure consistancy when path isn't supplied. | ||
| writable: false, | ||
| configurable: false, | ||
| enumerable: true | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not too different from setting the path. Let's make this block a function and reuse it for setting the path and relativePath.
Also, since the path is relative, /${file.name} should probably be ./${file.name}.
| ], []); | ||
| } | ||
|
|
||
| function fromDataTransferItem(item: DataTransferItem) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| function fromDataTransferItem(item: DataTransferItem) { | |
| function fromDataTransferItem(item: DataTransferItem, entry?: FileSystemEntry) { |
| return Promise.reject(`${item} is not a File`); | ||
| } | ||
| const fwp = toFileWithPath(file); | ||
| const fwp = toFileWithPath(file, fileAsEntry?.fullPath ?? undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const fwp = toFileWithPath(file, fileAsEntry?.fullPath ?? undefined); | |
| const fwp = toFileWithPath(file, entry?.fullPath ?? undefined); |
|
|
||
| let fileAsEntry: FileSystemEntry | null = null; | ||
| if (typeof item.webkitGetAsEntry === 'function') { | ||
| fileAsEntry = item.webkitGetAsEntry(); | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can get rid of this if on line 111 you add this:
else if (entry) {
return fromDataTransferItem(item, entry);
}
Because you already have the entry in the toFilePromises func.
|
@saul-prepared if you'd like, I could take over the PR and make the necessary changes. |
|
I've taken over the changes in #99. |
What kind of change does this PR introduce?
Did you add tests for your changes?
If relevant, did you update the documentation?
Summary
Explain the motivation for making this change. What existing problem does the pull request solve?
I created this Enhancement for this change.
Does this PR introduce a breaking change?
No
Other information