Skip to content
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: allow to specify the root of an upload #1131

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,10 @@ export class Uploader {
* Upload a file to the given path
* @param {string} destinationPath the destination path relative to the root folder. e.g. /foo/bar.txt
* @param {File} file the file to upload
* @param {string} root the root folder to upload to
*/
upload(destinationPath: string, file: File): PCancelable<Upload> {
const destinationFile = `${this.root}/${destinationPath.replace(/^\//, '')}`
upload(destinationPath: string, file: File, root?: string): PCancelable<Upload> {
const destinationFile = `${root || this.root}/${destinationPath.replace(/^\//, '')}`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it makes sense to do so, but this would also allow an empty root:

Suggested change
const destinationFile = `${root || this.root}/${destinationPath.replace(/^\//, '')}`
const destinationFile = `${root ?? this.root}/${destinationPath.replace(/^\//, '')}`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we should probably not allow empty root 👍


// Get the encoded source url to this object for requests purposes
const { origin } = new URL(destinationFile)
Expand Down
Loading