diff --git a/package.json b/package.json index ba02a83..6b4484d 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ }, "scripts": { "start": "node start.js", + "setup": "node scripts/setup.js", "addbot": "node addbot.js", "test": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap test/test.js | tap-dot", "test-slow": "cross-env FORCE_COLOR=true supertape --no-check-assertions-count --format tap --no-worker test/test.js -- --slow | tap-dot", diff --git a/readme.md b/readme.md index 992d0de..daebb1e 100644 --- a/readme.md +++ b/readme.md @@ -81,9 +81,9 @@ Follow these steps: 1. Install dependencies: `npm install` -1. Run `node scripts/seed.js` to check your setup and set the bot's initial state. It will prompt you for information. You only need to run this once ever. +1. Run `npm run setup` to check your setup and set the bot's initial state. It will prompt you for information. You only need to run this once ever. -1. Start the bridge: `npm start` +1. Start the bridge: `npm run start` 1. Add the bot to a server - use any *one* of the following commands for an invite link: * (in the REPL) `addbot` @@ -152,8 +152,8 @@ To get into the rooms on your Matrix account, use the `/invite [your mxid here]` │   └── *.js * Various files you can run once if you need them. └── scripts - * First time running a new bridge? Run this file to plant a seed, which will flourish into state for the bridge: - ├── seed.js + * First time running a new bridge? Run this file to set up prerequisites on the Matrix server: + ├── setup.js * Hopefully you won't need the rest of these. Code quality varies wildly. └── *.js diff --git a/scripts/seed.js b/scripts/setup.js old mode 100755 new mode 100644 similarity index 99% rename from scripts/seed.js rename to scripts/setup.js index f20afb7..2fb2dd0 --- a/scripts/seed.js +++ b/scripts/setup.js @@ -305,7 +305,7 @@ async function validateHomeserverOrigin(serverUrlPrompt, url) { } // Otherwise, it's the user's problem if (!guild) { - return die(`Error: The bot needs to upload some emojis. Please say where to upload them to. Run seed.js again with --emoji-guild=GUILD_ID`) + return die(`Error: The bot needs to upload some emojis. Please say where to upload them to. Run setup again with --emoji-guild=GUILD_ID`) } // Upload those emojis to the chosen location db.prepare("REPLACE INTO auto_emoji (name, emoji_id, guild_id) VALUES ('_', '_', ?)").run(guild.id) diff --git a/src/matrix/mreq.js b/src/matrix/mreq.js index 4707ae6..cdcf405 100644 --- a/src/matrix/mreq.js +++ b/src/matrix/mreq.js @@ -5,7 +5,7 @@ const mixin = require("@cloudrac3r/mixin-deep") const stream = require("stream") const getStream = require("get-stream") -const {reg} = require("./read-registration.js") +const {reg, writeRegistration} = require("./read-registration.js") const baseUrl = `${reg.ooye.server_origin}/_matrix` @@ -45,13 +45,15 @@ 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.") + if (root.error?.includes("Content-Length") || !reg.ooye.content_length_workaround) { + reg.ooye.content_length_workaround = true + const root = await mreq(method, url, body, extra) + console.error("OOYE cannot stream uploads to Synapse. The `content_length_workaround` option" + + "\nhas been activated in registration.yaml, which works around the problem, but" + + "\nhalves the speed of bridging d->m files. A better way to resolve this problem" + + "\nis to run an nginx reverse proxy to Synapse and re-run OOYE setup.") + writeRegistration(reg) + return root } delete opts.headers.Authorization throw new MatrixServerError(root, {baseUrl, url, ...opts})