mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2026-04-18 07:12:15 +00:00
Rewrite FileDigester to tidy up code, be able to delete files in OPFS onPageHide and on abort of file transfer
This commit is contained in:
@@ -619,4 +619,27 @@ function isUrlValid(url) {
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// polyfill for crypto.randomUUID()
|
||||
// Credits: @Briguy37 - https://stackoverflow.com/a/8809472/14678591
|
||||
function generateUUID() {
|
||||
return crypto && crypto.randomUUID()
|
||||
? crypto.randomUUID()
|
||||
: () => {
|
||||
let
|
||||
d = new Date().getTime(),
|
||||
d2 = ((typeof performance !== 'undefined') && performance.now && (performance.now() * 1000)) || 0;
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
||||
let r = Math.random() * 16;
|
||||
if (d > 0) {
|
||||
r = (d + r) % 16 | 0;
|
||||
d = Math.floor(d / 16);
|
||||
} else {
|
||||
r = (d2 + r) % 16 | 0;
|
||||
d2 = Math.floor(d2 / 16);
|
||||
}
|
||||
return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user