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:
schlagmichdoch 2024-07-14 18:04:03 +02:00
parent fa86212139
commit 76c47c9623
5 changed files with 346 additions and 127 deletions

View file

@ -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);
});
};
}