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

Fix impossible blob name check #19

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ export function uploadFileOrBlobAndReturnPath(
fileOrBlob: File | Blob,
options: Options = {},
): CancelablePromise<string> {
if (!(options.filename && 'name' in fileOrBlob)) {
let filename: string;

if (options.filename) {
// If a filename is explicitly provided, use it
filename = options.filename;
} else if (fileOrBlob instanceof File && fileOrBlob.name) {
// Files extend Blobs and may have a `name` property. Blobs never have names.
filename = fileOrBlob.name;
} else {
Comment on lines +37 to +45
Copy link
Member Author

@arcataroger arcataroger Mar 22, 2024

Choose a reason for hiding this comment

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

We could've also just changed the && to || in the original if, but then that will cause the later line filename = options.filename || fileOrBlob.name to have a TypeScript error, because blobs can never have names.

I think this is more explicit than adding a ts-ignore

throw new Error('Missing filename, please provide it as an option!');
}

const filename = options.filename || fileOrBlob.name;

let isCanceledBeforeUpload = false;
let uploadPromise: CancelablePromise<void> | undefined = undefined;

Expand Down
Loading