From 45de3f8be44e8d67d02c2ae931daa2882abafdf9 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 8 Jun 2025 22:52:07 +1200 Subject: [PATCH 1/2] Info API: Use HTTPS for avatar URLs --- src/web/routes/info.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/web/routes/info.js b/src/web/routes/info.js index b70ef84..0ccdeca 100644 --- a/src/web/routes/info.js +++ b/src/web/routes/info.js @@ -4,6 +4,9 @@ const {z} = require("zod") const {defineEventHandler, getValidatedQuery, H3Event} = require("h3") const {as, from, sync, select} = require("../../passthrough") +/** @type {import("../../m2d/converters/utils")} */ +const mUtils = sync.require("../../m2d/converters/utils") + /** * @param {H3Event} event * @returns {import("../../matrix/api")} @@ -53,7 +56,8 @@ as.router.get("/api/message", defineEventHandler(async event => { } } if (!matrix_author.displayname) matrix_author.displayname = mxid - if (!matrix_author.avatar_url) matrix_author.avatar_url = null + if (matrix_author.avatar_url) matrix_author.avatar_url = mUtils.getPublicUrlForMxc(matrix_author.avatar_url) + else matrix_author.avatar_url = null matrix_author["mxid"] = mxid } From 9ed20258e06b58b77ee51b28eb0d605271b24019 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Sun, 8 Jun 2025 22:52:43 +1200 Subject: [PATCH 2/2] Add documentation for info API --- docs/api.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 docs/api.md diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..98a6d1f --- /dev/null +++ b/docs/api.md @@ -0,0 +1,52 @@ +# API + +There is a web API for getting information about things that are bridged with Out Of Your Element. + +The base URL is the URL of the particular OOYE instance, for example, https://bridge.cadence.moe. + +No authentication is required. + +I'm happy to add more endpoints, just ask for them. + +## Endpoint: GET /api/message + +|Query parameter|Type|Description| +|---------------|----|-----------| +|`message_id`|regexp `/^[0-9]+$/`|Discord message ID to look up information for| + +Response: + +```typescript +{ + source: "matrix" | "discord" // Which platform the message originated on + matrix_author?: { // Only for Matrix messages; should be up-to-date rather than historical data + displayname: string, // Matrix user's current display name + avatar_url: string, // Absolute HTTP(S) URL to download the Matrix user's current avatar + mxid: string // Matrix user ID, can never change + }, + events: [ // Data about each individual event + { + metadata: { // Data from OOYE's database about how bridging was performed + sender: string, // Same as matrix user ID + event_id: string, // Unique ID of the event on Matrix, can never change + event_type: "m.room.message" | "m.sticker" | string, // Event type + event_subtype: "m.text" | "m.image" | "m.audio" | "m.video" | "m.file" | string | null, // For m.room.message events, this is the msgtype property + part: 0 | 1, // 0 if this is the first "part" of the message (e.g. this would be the text of a text message with an attachment) + reaction_part: 0 | 1, // 0 if this is the last "part" of the message (e.g. this would be the attachment of a text message with an attachment) + room_id: string, // Room ID that the event was sent in, linked to the Discord channel + source: number + }, + raw: { // Raw historical event data from the Matrix API. Contains at least these properties, but highly depends on what the client sent + content: any, // The only non-metadata property, entirely client-generated + type: string, + room_id: string, + sender: string, + origin_server_ts: number, + unsigned?: any, + event_id: string, + user_id: string + } + } + ] +} +```