|
436 | 436 | 'Authorization': 'Nostr ' + token |
437 | 437 | }; |
438 | 438 |
|
439 | | - // Collect body if it's an async iterable |
| 439 | + // Collect body if it's an async iterable or array |
440 | 440 | 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 | + } |
452 | 464 | } |
| 465 | + // If already Uint8Array, use as-is |
453 | 466 | } |
454 | 467 |
|
455 | 468 | if (requestBody) { |
|
0 commit comments