From 706b37669b59835f678d431bc28372f40005c344 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sat, 20 Jan 2024 17:25:58 +1300 Subject: [PATCH] Move Content-Length detection logic --- matrix/mreq.js | 8 ++++++++ scripts/seed.js | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/matrix/mreq.js b/matrix/mreq.js index 70d9ac7..d515846 100644 --- a/matrix/mreq.js +++ b/matrix/mreq.js @@ -48,6 +48,14 @@ async function mreq(method, url, body, extra = {}) { const root = await res.json() if (!res.ok || root.errcode) { + if (root.error?.includes("Content-Length")) { + console.error(`OOYE cannot stream uploads to Synapse. Please choose one of these workarounds:` + + `\n * Run an nginx reverse proxy to Synapse, and point registration.yaml's` + + `\n \`server_origin\` to nginx` + + `\n * Set \`content_length_workaround: true\` in registration.yaml (this will` + + `\n halve the speed of bridging d->m files)`) + throw new Error("Synapse is not accepting stream uploads, see the message above.") + } delete opts.headers.Authorization throw new MatrixServerError(root, {baseUrl, url, ...opts}) } diff --git a/scripts/seed.js b/scripts/seed.js index 20cb5dd..1a21490 100644 --- a/scripts/seed.js +++ b/scripts/seed.js @@ -73,12 +73,6 @@ async function uploadAutoEmoji(guild, name, filename) { } catch (e) { if (e.errcode === "M_USER_IN_USE" || e.data?.error === "Internal server error") { // "Internal server error" is the only OK error because older versions of Synapse say this if you try to register the same username twice. - } else if (e.data?.error?.includes("Content-Length")) { - die(`OOYE cannot stream uploads to Synapse. Please choose one of these workarounds:` - + `\n * Run an nginx reverse proxy to Synapse, and point registration.yaml's` - + `\n \`server_origin\` to nginx` - + `\n * Set \`content_length_workaround: true\` in registration.yaml (this will` - + `\n halve the speed of bridging d->m files)`) } else { throw e }