Skip to content

Commit f288c9a

Browse files
Fix: handle Array body type by concatenating to Uint8Array
1 parent d2016a5 commit f288c9a

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

index.html

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -436,20 +436,33 @@
436436
'Authorization': 'Nostr ' + token
437437
};
438438

439-
// Collect body if it's an async iterable
439+
// Collect body if it's an async iterable or array
440440
let requestBody = body;
441-
if (body && typeof body[Symbol.asyncIterator] === 'function') {
442-
const chunks = [];
443-
for await (const chunk of body) {
444-
chunks.push(chunk);
445-
}
446-
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
447-
requestBody = new Uint8Array(totalLength);
448-
let offset = 0;
449-
for (const chunk of chunks) {
450-
requestBody.set(chunk, offset);
451-
offset += chunk.length;
441+
if (body) {
442+
if (typeof body[Symbol.asyncIterator] === 'function') {
443+
// Async iterable - collect chunks
444+
const chunks = [];
445+
for await (const chunk of body) {
446+
chunks.push(chunk);
447+
}
448+
const totalLength = chunks.reduce((sum, chunk) => sum + chunk.length, 0);
449+
requestBody = new Uint8Array(totalLength);
450+
let offset = 0;
451+
for (const chunk of chunks) {
452+
requestBody.set(chunk, offset);
453+
offset += chunk.length;
454+
}
455+
} else if (Array.isArray(body)) {
456+
// Regular array of Uint8Arrays - concatenate
457+
const totalLength = body.reduce((sum, chunk) => sum + chunk.length, 0);
458+
requestBody = new Uint8Array(totalLength);
459+
let offset = 0;
460+
for (const chunk of body) {
461+
requestBody.set(chunk, offset);
462+
offset += chunk.length;
463+
}
452464
}
465+
// If already Uint8Array, use as-is
453466
}
454467

455468
if (requestBody) {

0 commit comments

Comments
 (0)