Skip to content

Commit

Permalink
Add a fallback to the crypto.randomUUID API
Browse files Browse the repository at this point in the history
  • Loading branch information
doberkofler committed Nov 5, 2024
1 parent 8546f88 commit 01111a8
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit 01111a8

Please sign in to comment.