sign urls in gateway
This commit is contained in:
parent
4395648c5b
commit
9756ed227b
@ -28,6 +28,7 @@ import { Message } from "./Message";
|
||||
import { Deflate, Inflate } from "fast-zlib";
|
||||
import { URL } from "url";
|
||||
import { Config, ErlpackType } from "@spacebar/util";
|
||||
import { Request } from "express";
|
||||
|
||||
let erlpack: ErlpackType | null = null;
|
||||
try {
|
||||
@ -51,6 +52,7 @@ export async function Connection(
|
||||
: request.socket.remoteAddress;
|
||||
|
||||
socket.ipAddress = ipAddress;
|
||||
socket.request = request as unknown as Request;
|
||||
|
||||
//Create session ID when the connection is opened. This allows gateway dump to group the initial websocket messages with the rest of the conversation.
|
||||
const session_id = genSessionId();
|
||||
|
||||
@ -27,6 +27,7 @@ import {
|
||||
EVENTEnum,
|
||||
Relationship,
|
||||
RelationshipType,
|
||||
Message,
|
||||
} from "@spacebar/util";
|
||||
import { OPCODES } from "../util/Constants";
|
||||
import { Send } from "../util/Send";
|
||||
@ -160,7 +161,7 @@ export async function setupListener(this: WebSocket) {
|
||||
|
||||
// TODO: only subscribe for events that are in the connection intents
|
||||
async function consume(this: WebSocket, opts: EventOpts) {
|
||||
const { data, event } = opts;
|
||||
let { data, event } = opts;
|
||||
const id = data.id as string;
|
||||
const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm
|
||||
|
||||
@ -285,6 +286,17 @@ async function consume(this: WebSocket, opts: EventOpts) {
|
||||
break;
|
||||
}
|
||||
|
||||
// data rewrites, e.g. signed attachment URLs
|
||||
switch (event) {
|
||||
case "MESSAGE_CREATE":
|
||||
case "MESSAGE_UPDATE":
|
||||
if(data["attachments"])
|
||||
data["attachments"] = Message.prototype.withSignedAttachments.call(data, this.request).attachments;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
await Send(this, {
|
||||
op: OPCODES.Dispatch,
|
||||
t: event,
|
||||
|
||||
@ -20,6 +20,7 @@ import { Intents, ListenEventOpts, Permissions } from "@spacebar/util";
|
||||
import WS from "ws";
|
||||
import { Deflate, Inflate } from "fast-zlib";
|
||||
import { Capabilities } from "./Capabilities";
|
||||
import { Request } from "express";
|
||||
|
||||
export interface WebSocket extends WS {
|
||||
version: number;
|
||||
@ -42,4 +43,9 @@ export interface WebSocket extends WS {
|
||||
listen_options: ListenEventOpts;
|
||||
capabilities?: Capabilities;
|
||||
large_threshold: number;
|
||||
/**
|
||||
* The request object for the WebSocket connection.
|
||||
* WARNING: This is not a proper Express Request object, it may be missing expected properties.
|
||||
*/
|
||||
request: Request; // For signed attachment URLs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user