mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-15 17:12:59 -04:00
22 lines
609 B
JavaScript
22 lines
609 B
JavaScript
// Base64 and auth helpers for upload and WHIP requests.
|
|
export function bytesToBase64(bytes) {
|
|
let binary = '';
|
|
const chunkSize = 0x8000;
|
|
for (let i = 0; i < bytes.length; i += chunkSize) {
|
|
const chunk = bytes.subarray(i, i + chunkSize);
|
|
binary += String.fromCharCode(...chunk);
|
|
}
|
|
return btoa(binary);
|
|
}
|
|
|
|
function encodeBase64(value) {
|
|
if (typeof btoa === 'function') return btoa(value);
|
|
return '';
|
|
}
|
|
|
|
export function buildAuthHeader(token) {
|
|
if (!token) return {};
|
|
const encoded = encodeBase64(`${token}:${token}`);
|
|
return encoded ? { Authorization: `Basic ${encoded}` } : {};
|
|
}
|