mirror of
https://github.com/zitadel/zitadel.git
synced 2025-01-08 19:27:41 +00:00
fix(console): url safe base64 to array buffer (#6019)
fix: console base64 to array buffer Co-authored-by: Livio Spring <livio.a@gmail.com>
This commit is contained in:
parent
5693e40930
commit
e39d1b7d82
@ -1,9 +1,31 @@
|
|||||||
export function _base64ToArrayBuffer(base64: string): any {
|
export function _base64ToArrayBuffer(thing: any) {
|
||||||
const binaryString = atob(base64);
|
if (typeof thing === 'string') {
|
||||||
const len = binaryString.length;
|
// base64url to base64
|
||||||
const bytes = new Uint8Array(len);
|
thing = thing.replace(/-/g, '+').replace(/_/g, '/');
|
||||||
for (let i = 0; i < len; i++) {
|
|
||||||
bytes[i] = binaryString.charCodeAt(i);
|
// base64 to Uint8Array
|
||||||
|
var str = window.atob(thing);
|
||||||
|
var bytes = new Uint8Array(str.length);
|
||||||
|
for (var i = 0; i < str.length; i++) {
|
||||||
|
bytes[i] = str.charCodeAt(i);
|
||||||
}
|
}
|
||||||
return bytes.buffer;
|
thing = bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Array to Uint8Array
|
||||||
|
if (Array.isArray(thing)) {
|
||||||
|
thing = new Uint8Array(thing);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Uint8Array to ArrayBuffer
|
||||||
|
if (thing instanceof Uint8Array) {
|
||||||
|
thing = thing.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// error if none of the above worked
|
||||||
|
if (!(thing instanceof ArrayBuffer)) {
|
||||||
|
throw new TypeError('could not coerce to ArrayBuffer');
|
||||||
|
}
|
||||||
|
|
||||||
|
return thing;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user