From b0ded8e289e188368431dd62450f1d107eb733f8 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 13 Feb 2025 01:14:29 +1300 Subject: [PATCH] Fix d->m file uploads --- src/matrix/mreq.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/matrix/mreq.js b/src/matrix/mreq.js index feb13b2..8d0d69d 100644 --- a/src/matrix/mreq.js +++ b/src/matrix/mreq.js @@ -2,6 +2,7 @@ const mixin = require("@cloudrac3r/mixin-deep") const stream = require("stream") +const {ReadableStream} = require("stream/web") const getStream = require("get-stream") const {reg, writeRegistration} = require("./read-registration.js") @@ -30,18 +31,18 @@ async function mreq(method, url, body, extra = {}) { } else if (body instanceof stream.Readable && reg.ooye.content_length_workaround) { body = await getStream.buffer(body) } else if (body instanceof ReadableStream && reg.ooye.content_length_workaround) { - body = await stream.consumers.buffer(body) + body = await stream.consumers.buffer(stream.Readable.fromWeb(body)) } /** @type {RequestInit} */ - const opts = { + const opts = mixin({ method, body, headers: { Authorization: `Bearer ${reg.as_token}` }, - ...extra - } + ...(body && {duplex: "half"}), // https://github.com/octokit/request.js/pull/571/files + }, extra) // console.log(baseUrl + url, opts) const res = await fetch(baseUrl + url, opts) const root = await res.json()