From dda35d052e82b7c07870a45dc45c718d32ffd82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tadeusz=20=E2=80=9Etadzik=E2=80=9D=20So=C5=9Bnierz?= Date: Fri, 6 Sep 2024 11:19:26 +0200 Subject: [PATCH] Move mediaProxy configuration to the top level This bypasses its weird interactions with ApplyConfig which would sometimes cause it to not be initialized properly. --- config.sample.yaml | 21 +++++++++++---------- config/config.schema.yaml | 28 ++++++++++++++-------------- src/Config.ts | 21 +++++++++------------ src/Program.ts | 2 +- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/config.sample.yaml b/config.sample.yaml index e56516d..879515f 100644 --- a/config.sample.yaml +++ b/config.sample.yaml @@ -9,16 +9,17 @@ bridge: appservicePort: 9555 # Config for the media proxy # required to serve publically accessible URLs to authenticated Matrix media - mediaProxy: - # To generate a .jwk file: - # $ node src/generate-signing-key.js > signingkey.jwk - signingKeyPath: "signingkey.jwk" - # How long should the generated URLs be valid for - ttlSeconds: 3600 - # The port for the media proxy to listen on - bindPort: 11111 - # The publically accessible URL to the media proxy - publicUrl: "https://bifrost.bridge/media" + +mediaProxy: + # To generate a .jwk file: + # $ node src/generate-signing-key.js > signingkey.jwk + signingKeyPath: "signingkey.jwk" + # How long should the generated URLs be valid for + ttlSeconds: 3600 + # The port for the media proxy to listen on + bindPort: 11111 + # The publically accessible URL to the media proxy + publicUrl: "https://bifrost.bridge/media" roomRules: [] # - room: "#badroom:example.com" diff --git a/config/config.schema.yaml b/config/config.schema.yaml index e3aa53a..07e7d42 100644 --- a/config/config.schema.yaml +++ b/config/config.schema.yaml @@ -1,11 +1,11 @@ "$schema": "http://json-schema.org/draft-07/schema#" "$id": "http://matrix.org/bifrost/schema" type: object -required: ["bridge", "datastore", "purple", "portals"] +required: ["bridge", "mediaProxy", "datastore", "purple", "portals"] properties: bridge: type: object - required: ["domain", "homeserverUrl", "userPrefix", "mediaProxy"] + required: ["domain", "homeserverUrl", "userPrefix"] properties: domain: type: string @@ -15,18 +15,18 @@ properties: type: string appservicePort: type: number - mediaProxy: - type: "object" - properties: - signingKeyPath: - type: "string" - ttlSeconds: - type: "integer" - bindPort: - type: "integer" - publicUrl: - type: "string" - required: ["signingKeyPath", "ttlSeconds", "bindPort", "publicUrl"] + mediaProxy: + type: "object" + properties: + signingKeyPath: + type: "string" + ttlSeconds: + type: "integer" + bindPort: + type: "integer" + publicUrl: + type: "string" + required: ["signingKeyPath", "ttlSeconds", "bindPort", "publicUrl"] datastore: required: ["engine"] type: "object" diff --git a/src/Config.ts b/src/Config.ts index 1f98f3e..ab25378 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -14,14 +14,10 @@ export class Config { homeserverUrl: "", userPrefix: "_bifrost_", appservicePort: 9555, - mediaProxy: { - signingKeyPath: "", - ttlSeconds: 0, - bindPort: 0, - publicUrl: "" - }, }; + public readonly mediaProxy: IMediaProxy; + public readonly roomRules: IConfigRoomRule[] = []; public readonly datastore: IConfigDatastore = { @@ -109,12 +105,13 @@ export interface IConfigBridge { homeserverUrl: string; userPrefix: string; appservicePort?: number; - mediaProxy: { - signingKeyPath: string; - ttlSeconds: number; - bindPort: number; - publicUrl: string; - }, +} + +export interface IMediaProxy { + signingKeyPath: string; + ttlSeconds: number; + bindPort: number; + publicUrl: string; } export interface IConfigPurple { diff --git a/src/Program.ts b/src/Program.ts index 21928a3..064dca7 100644 --- a/src/Program.ts +++ b/src/Program.ts @@ -92,7 +92,7 @@ class Program { } private async initialiseMediaProxy(): Promise { - const config = this.config.bridge.mediaProxy; + const config = this.config.mediaProxy; const jwk = JSON.parse(fs.readFileSync(config.signingKeyPath, "utf8").toString()); const signingKey = await webcrypto.subtle.importKey('jwk', jwk, { name: 'HMAC',