Merge branch 'hotfix-v1.5.1'
This commit is contained in:
commit
0f25e73d67
8 changed files with 48 additions and 4 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
const fetch = require("node-fetch").default
|
const fetch = require("node-fetch").default
|
||||||
const mixin = require("mixin-deep")
|
const mixin = require("mixin-deep")
|
||||||
|
const stream = require("stream")
|
||||||
|
const getStream = require("get-stream")
|
||||||
|
|
||||||
const passthrough = require("../passthrough")
|
const passthrough = require("../passthrough")
|
||||||
const { sync } = passthrough
|
const { sync } = passthrough
|
||||||
|
@ -27,9 +29,15 @@ class MatrixServerError extends Error {
|
||||||
* @param {any} [extra]
|
* @param {any} [extra]
|
||||||
*/
|
*/
|
||||||
async function mreq(method, url, body, extra = {}) {
|
async function mreq(method, url, body, extra = {}) {
|
||||||
|
if (body == undefined || Object.is(body.constructor, Object)) {
|
||||||
|
body = JSON.stringify(body)
|
||||||
|
} else if (body instanceof stream.Readable && reg.ooye.content_length_workaround) {
|
||||||
|
body = await getStream.buffer(body)
|
||||||
|
}
|
||||||
|
|
||||||
const opts = mixin({
|
const opts = mixin({
|
||||||
method,
|
method,
|
||||||
body: (body == undefined || Object.is(body.constructor, Object)) ? JSON.stringify(body) : body,
|
body,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${reg.as_token}`
|
Authorization: `Bearer ${reg.as_token}`
|
||||||
}
|
}
|
||||||
|
@ -39,7 +47,18 @@ async function mreq(method, url, body, extra = {}) {
|
||||||
const res = await fetch(baseUrl + url, opts)
|
const res = await fetch(baseUrl + url, opts)
|
||||||
const root = await res.json()
|
const root = await res.json()
|
||||||
|
|
||||||
if (!res.ok || root.errcode) throw new MatrixServerError(root, {baseUrl, url, ...opts})
|
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})
|
||||||
|
}
|
||||||
return root
|
return root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
package-lock.json
generated
12
package-lock.json
generated
|
@ -16,6 +16,7 @@
|
||||||
"deep-equal": "^2.2.3",
|
"deep-equal": "^2.2.3",
|
||||||
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#de519353668c87ecc8c543e9749093481bc72ff8",
|
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#de519353668c87ecc8c543e9749093481bc72ff8",
|
||||||
"entities": "^4.5.0",
|
"entities": "^4.5.0",
|
||||||
|
"get-stream": "^6.0.1",
|
||||||
"giframe": "github:cloudrac3r/giframe#v0.4.1",
|
"giframe": "github:cloudrac3r/giframe#v0.4.1",
|
||||||
"heatsync": "^2.4.1",
|
"heatsync": "^2.4.1",
|
||||||
"html-template-tag": "github:cloudrac3r/html-template-tag#v5.0",
|
"html-template-tag": "github:cloudrac3r/html-template-tag#v5.0",
|
||||||
|
@ -1456,6 +1457,17 @@
|
||||||
"source-map": "^0.6.1"
|
"source-map": "^0.6.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/get-stream": {
|
||||||
|
"version": "6.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
|
||||||
|
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/giframe": {
|
"node_modules/giframe": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "git+ssh://git@github.com/cloudrac3r/giframe.git#1630f4d3b2bf5acd197409c85edd11e0da72d0a1",
|
"resolved": "git+ssh://git@github.com/cloudrac3r/giframe.git#1630f4d3b2bf5acd197409c85edd11e0da72d0a1",
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
"deep-equal": "^2.2.3",
|
"deep-equal": "^2.2.3",
|
||||||
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#de519353668c87ecc8c543e9749093481bc72ff8",
|
"discord-markdown": "git+https://git.sr.ht/~cadence/nodejs-discord-markdown#de519353668c87ecc8c543e9749093481bc72ff8",
|
||||||
"entities": "^4.5.0",
|
"entities": "^4.5.0",
|
||||||
|
"get-stream": "^6.0.1",
|
||||||
"giframe": "github:cloudrac3r/giframe#v0.4.1",
|
"giframe": "github:cloudrac3r/giframe#v0.4.1",
|
||||||
"heatsync": "^2.4.1",
|
"heatsync": "^2.4.1",
|
||||||
"html-template-tag": "github:cloudrac3r/html-template-tag#v5.0",
|
"html-template-tag": "github:cloudrac3r/html-template-tag#v5.0",
|
||||||
|
|
|
@ -96,6 +96,10 @@ Follow these steps:
|
||||||
* $ `npm run addbot`
|
* $ `npm run addbot`
|
||||||
* $ `./addbot.sh`
|
* $ `./addbot.sh`
|
||||||
|
|
||||||
|
Now any message on Discord will create the corresponding rooms on Matrix-side. After the rooms have been created, Matrix and Discord users can chat back and forth.
|
||||||
|
|
||||||
|
To get into the rooms on your Matrix account, either add yourself to `invite` in `registration.yaml`, or use the `//invite [your mxid here]` command on Discord.
|
||||||
|
|
||||||
# Development setup
|
# Development setup
|
||||||
|
|
||||||
* Be sure to install dependencies with `--save-dev` so you can run the tests.
|
* Be sure to install dependencies with `--save-dev` so you can run the tests.
|
||||||
|
@ -164,6 +168,7 @@ Follow these steps:
|
||||||
* (8) snowtransfer: Discord API library with bring-your-own-caching that I trust.
|
* (8) snowtransfer: Discord API library with bring-your-own-caching that I trust.
|
||||||
* (0) deep-equal: It's already pulled in by supertape.
|
* (0) deep-equal: It's already pulled in by supertape.
|
||||||
* (1) discord-markdown: This is my fork!
|
* (1) discord-markdown: This is my fork!
|
||||||
|
* (0) get-stream: Only needed if content_length_workaround is true.
|
||||||
* (0) giframe: This is my fork!
|
* (0) giframe: This is my fork!
|
||||||
* (1) heatsync: Module hot-reloader that I trust.
|
* (1) heatsync: Module hot-reloader that I trust.
|
||||||
* (0) entities: Looks fine. No dependencies.
|
* (0) entities: Looks fine. No dependencies.
|
||||||
|
|
|
@ -18,6 +18,7 @@ ooye:
|
||||||
max_file_size: 5000000
|
max_file_size: 5000000
|
||||||
server_name: [the part after the colon in your matrix id, like cadence.moe]
|
server_name: [the part after the colon in your matrix id, like cadence.moe]
|
||||||
server_origin: [the full protocol and domain of your actual matrix server's location, with no trailing slash, like https://matrix.cadence.moe]
|
server_origin: [the full protocol and domain of your actual matrix server's location, with no trailing slash, like https://matrix.cadence.moe]
|
||||||
|
content_length_workaround: false
|
||||||
invite:
|
invite:
|
||||||
# uncomment this to auto-invite the named user to newly created spaces and mark them as admin (PL 100) everywhere
|
# uncomment this to auto-invite the named user to newly created spaces and mark them as admin (PL 100) everywhere
|
||||||
# - @cadence:cadence.moe
|
# - '@cadence:cadence.moe'
|
||||||
|
|
|
@ -71,7 +71,11 @@ async function uploadAutoEmoji(guild, name, filename) {
|
||||||
try {
|
try {
|
||||||
await api.register(reg.sender_localpart)
|
await api.register(reg.sender_localpart)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e.errcode === "M_USER_IN_USE" || e.data?.error !== "Internal server error") throw e // "Internal server error" is the only OK error because Synapse says this if you try to register the same username twice.
|
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 {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// upload initial images...
|
// upload initial images...
|
||||||
|
|
|
@ -14,6 +14,7 @@ const db = new sqlite(":memory:")
|
||||||
|
|
||||||
const reg = require("../matrix/read-registration")
|
const reg = require("../matrix/read-registration")
|
||||||
reg.ooye.server_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded
|
reg.ooye.server_origin = "https://matrix.cadence.moe" // so that tests will pass even when hard-coded
|
||||||
|
reg.ooye.server_name = "cadence.moe"
|
||||||
reg.ooye.invite = ["@test_auto_invite:example.org"]
|
reg.ooye.invite = ["@test_auto_invite:example.org"]
|
||||||
|
|
||||||
const sync = new HeatSync({watchFS: false})
|
const sync = new HeatSync({watchFS: false})
|
||||||
|
|
1
types.d.ts
vendored
1
types.d.ts
vendored
|
@ -21,6 +21,7 @@ export type AppServiceRegistrationConfig = {
|
||||||
max_file_size: number
|
max_file_size: number
|
||||||
server_name: string
|
server_name: string
|
||||||
server_origin: string
|
server_origin: string
|
||||||
|
content_length_workaround: boolean
|
||||||
invite: string[]
|
invite: string[]
|
||||||
}
|
}
|
||||||
old_bridge?: {
|
old_bridge?: {
|
||||||
|
|
Loading…
Reference in a new issue