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

Add a fallback to the crypto.randomUUID API #24

Merged
merged 2 commits into from
Nov 7, 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
13 changes: 12 additions & 1 deletion src/dropzone.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ export default class Dropzone extends Emitter {
addFile(file) {
file.upload = {
// note: this only works if window.isSecureContext is true, which includes localhost in http
uuid: self.crypto.randomUUID(),
uuid: window.isSecureContext ? self.crypto.randomUUID() : Dropzone.uuidv4(),
progress: 0,
// Setting the total upload size to file.size for the beginning
// It's actual different than the size to be transmitted.
Expand Down Expand Up @@ -1707,6 +1707,17 @@ export default class Dropzone extends Emitter {
return this.processQueue();
}
}

static uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
/[xy]/g,
function (c) {
let r = (Math.random() * 16) | 0,
v = c === "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
}
);
}
}
Dropzone.initClass();

Expand Down