Fix my homeserver being hard-coded
This commit is contained in:
parent
acee80ce52
commit
714c31d230
7 changed files with 15 additions and 9 deletions
|
@ -3,6 +3,8 @@
|
|||
const assert = require("assert").strict
|
||||
const util = require("util")
|
||||
const DiscordTypes = require("discord-api-types/v10")
|
||||
const reg = require("../matrix/read-registration")
|
||||
|
||||
const {discord, sync, db} = require("../passthrough")
|
||||
/** @type {import("../matrix/api")}) */
|
||||
const api = sync.require("../matrix/api")
|
||||
|
@ -86,7 +88,7 @@ const commands = [{
|
|||
const avatarEvent = await api.getStateEvent(roomID, "m.room.avatar", "")
|
||||
const avatarURLParts = avatarEvent?.url.match(/^mxc:\/\/([^/]+)\/(\w+)$/)
|
||||
let currentAvatarMessage =
|
||||
( avatarURLParts ? `Current room-specific avatar: https://matrix.cadence.moe/_matrix/media/r0/download/${avatarURLParts[1]}/${avatarURLParts[2]}`
|
||||
( avatarURLParts ? `Current room-specific avatar: ${reg.ooye.server_origin}/_matrix/media/r0/download/${avatarURLParts[1]}/${avatarURLParts[2]}`
|
||||
: "No avatar. Now's your time to strike. Use `//icon` again with a link or upload to set the room-specific avatar.")
|
||||
|
||||
// Next potential avatar
|
||||
|
|
|
@ -25,7 +25,7 @@ function eventSenderIsFromDiscord(sender) {
|
|||
*/
|
||||
function getPublicUrlForMxc(mxc) {
|
||||
const avatarURLParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/)
|
||||
if (avatarURLParts) return `https://matrix.cadence.moe/_matrix/media/r0/download/${avatarURLParts[1]}/${avatarURLParts[2]}`
|
||||
if (avatarURLParts) return `${reg.ooye.server_origin}/_matrix/media/r0/download/${avatarURLParts[1]}/${avatarURLParts[2]}`
|
||||
else return null
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ const { sync } = passthrough
|
|||
/** @type {import("./read-registration")} */
|
||||
const reg = sync.require("./read-registration.js")
|
||||
|
||||
const baseUrl = "https://matrix.cadence.moe/_matrix"
|
||||
const baseUrl = `${reg.ooye.server_origin}/_matrix`
|
||||
|
||||
class MatrixServerError extends Error {
|
||||
constructor(data, opts) {
|
||||
|
|
|
@ -51,15 +51,15 @@ Most features you'd expect in both directions, plus a little extra spice:
|
|||
|
||||
Node.js version 18 or later is required: https://nodejs.org/en/download/releases (the matrix-appservice dependency demands 18)
|
||||
|
||||
Install dependencies: `npm install --save-dev`
|
||||
Install dependencies: `npm install --save-dev` (only need --save-dev if you will run the automated tests)
|
||||
|
||||
Copy `config.example.js` to `config.js` and fill in Discord token.
|
||||
|
||||
Copy `registration.example.yaml` to `registration.yaml` and fill in bracketed values. Register it in Synapse's `homeserver.yaml` through the usual appservice installation process, then restart Synapse.
|
||||
Copy `registration.example.yaml` to `registration.yaml` and fill in bracketed values. You could generate each hex string with `dd if=/dev/urandom bs=32 count=1 2> /dev/null | basenc --base16 | dd conv=lcase 2> /dev/null`. Register the registration in Synapse's `homeserver.yaml` through the usual appservice installation process, then restart Synapse.
|
||||
|
||||
If developing on a different computer to the one running the homeserver, use SSH port forwarding so that Synapse can connect on its `localhost:6693` to reach the running bridge on your computer. Example: `ssh -T -v -R 6693:localhost:6693 username@matrix.cadence.moe`
|
||||
If developing on a different computer to the one running the homeserver, use SSH port forwarding so that Synapse can connect on its `localhost:6693` to reach the running bridge on your computer. Example: `ssh -T -v -R 6693:localhost:6693 me@matrix.cadence.moe`
|
||||
|
||||
Run `node scripts/seed.js` to check your setup, then create the database and server state (only need to run this once ever)
|
||||
Run `node scripts/seed.js` to check your setup, create the database and server state (only need to run this once ever)
|
||||
|
||||
Make sure the tests work: `npm t`
|
||||
|
||||
|
|
|
@ -17,3 +17,4 @@ ooye:
|
|||
namespace_prefix: _ooye_
|
||||
max_file_size: 5000000
|
||||
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]
|
||||
|
|
|
@ -22,8 +22,10 @@ const utils = require("../m2d/converters/utils")
|
|||
const mxid = `@${reg.sender_localpart}:${reg.ooye.server_name}`
|
||||
|
||||
// ensure registration is correctly set...
|
||||
assert(reg.sender_localpart.startsWith(reg.ooye.namespace_prefix))
|
||||
assert(utils.eventSenderIsFromDiscord(mxid))
|
||||
assert(reg.sender_localpart.startsWith(reg.ooye.namespace_prefix)) // appservice's localpart must be in the namespace it controls
|
||||
assert(utils.eventSenderIsFromDiscord(mxid)) // appservice's mxid must be in the namespace it controls
|
||||
assert(reg.ooye.server_origin.match(/^https?:\/\//)) // must start with http or https
|
||||
assert.notEqual(reg.ooye.server_origin.slice(-1), "/") // must not end in slash
|
||||
|
||||
// database ddl...
|
||||
db.exec(fs.readFileSync("db/ooye-schema.sql", "utf8"))
|
||||
|
|
1
types.d.ts
vendored
1
types.d.ts
vendored
|
@ -20,6 +20,7 @@ export type AppServiceRegistrationConfig = {
|
|||
namespace_prefix: string
|
||||
max_file_size: number
|
||||
server_name: string
|
||||
server_origin: string
|
||||
}
|
||||
old_bridge?: {
|
||||
as_token: string
|
||||
|
|
Loading…
Reference in a new issue