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 { Deflate, Inflate } from "fast-zlib";
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { Config, ErlpackType } from "@spacebar/util";
|
import { Config, ErlpackType } from "@spacebar/util";
|
||||||
|
import { Request } from "express";
|
||||||
|
|
||||||
let erlpack: ErlpackType | null = null;
|
let erlpack: ErlpackType | null = null;
|
||||||
try {
|
try {
|
||||||
@ -51,6 +52,7 @@ export async function Connection(
|
|||||||
: request.socket.remoteAddress;
|
: request.socket.remoteAddress;
|
||||||
|
|
||||||
socket.ipAddress = ipAddress;
|
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.
|
//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();
|
const session_id = genSessionId();
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import {
|
|||||||
EVENTEnum,
|
EVENTEnum,
|
||||||
Relationship,
|
Relationship,
|
||||||
RelationshipType,
|
RelationshipType,
|
||||||
|
Message,
|
||||||
} from "@spacebar/util";
|
} from "@spacebar/util";
|
||||||
import { OPCODES } from "../util/Constants";
|
import { OPCODES } from "../util/Constants";
|
||||||
import { Send } from "../util/Send";
|
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
|
// TODO: only subscribe for events that are in the connection intents
|
||||||
async function consume(this: WebSocket, opts: EventOpts) {
|
async function consume(this: WebSocket, opts: EventOpts) {
|
||||||
const { data, event } = opts;
|
let { data, event } = opts;
|
||||||
const id = data.id as string;
|
const id = data.id as string;
|
||||||
const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm
|
const permission = this.permissions[id] || new Permissions("ADMINISTRATOR"); // default permission for dm
|
||||||
|
|
||||||
@ -285,6 +286,17 @@ async function consume(this: WebSocket, opts: EventOpts) {
|
|||||||
break;
|
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, {
|
await Send(this, {
|
||||||
op: OPCODES.Dispatch,
|
op: OPCODES.Dispatch,
|
||||||
t: event,
|
t: event,
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import { Intents, ListenEventOpts, Permissions } from "@spacebar/util";
|
|||||||
import WS from "ws";
|
import WS from "ws";
|
||||||
import { Deflate, Inflate } from "fast-zlib";
|
import { Deflate, Inflate } from "fast-zlib";
|
||||||
import { Capabilities } from "./Capabilities";
|
import { Capabilities } from "./Capabilities";
|
||||||
|
import { Request } from "express";
|
||||||
|
|
||||||
export interface WebSocket extends WS {
|
export interface WebSocket extends WS {
|
||||||
version: number;
|
version: number;
|
||||||
@ -42,4 +43,9 @@ export interface WebSocket extends WS {
|
|||||||
listen_options: ListenEventOpts;
|
listen_options: ListenEventOpts;
|
||||||
capabilities?: Capabilities;
|
capabilities?: Capabilities;
|
||||||
large_threshold: number;
|
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