mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-06-15 10:44:52 -04:00
Centralize evaluation of URL parameters to clean up code and remove redundancies, and streamline Base64Dialog class
This commit is contained in:
parent
cb86ce0e39
commit
10b658e2e9
6 changed files with 195 additions and 179 deletions
|
@ -504,4 +504,29 @@ function getResizedImageDataUrl(file, width = undefined, height = undefined, qua
|
|||
}
|
||||
image.onerror = _ => reject(`Could not create an image thumbnail from type ${file.type}`);
|
||||
})
|
||||
}
|
||||
|
||||
async function decodeBase64Files(base64) {
|
||||
if (!base64) throw new Error('Base64 is empty');
|
||||
|
||||
let bstr = atob(base64), n = bstr.length, u8arr = new Uint8Array(n);
|
||||
while (n--) {
|
||||
u8arr[n] = bstr.charCodeAt(n);
|
||||
}
|
||||
|
||||
const zipBlob = new File([u8arr], 'archive.zip');
|
||||
|
||||
let files = [];
|
||||
const zipEntries = await zipper.getEntries(zipBlob);
|
||||
for (let i = 0; i < zipEntries.length; i++) {
|
||||
let fileBlob = await zipper.getData(zipEntries[i]);
|
||||
files.push(new File([fileBlob], zipEntries[i].filename));
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
async function decodeBase64Text(base64) {
|
||||
if (!base64) throw new Error('Base64 is empty');
|
||||
|
||||
return decodeURIComponent(escape(window.atob(base64)))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue