Skip to content

Commit

Permalink
support specific payload sizes via env var MAX_PAYLOAD_SIZE_MB
Browse files Browse the repository at this point in the history
  • Loading branch information
targoninc-alex committed Jun 30, 2024
1 parent d948524 commit f807205
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ SESSION_SECRET=mysecret
ALLOW_FREE_REGISTRATION=true
UI_DEPLOYMENT_URL=http://localhost:3001
WEBSOCKET_URL=ws://127.0.0.1:8912
FILE_FOLDER=path/to/files/folder (will be created if it doesn't exist)
MAX_PAYLOAD_SIZE_MB=10
```

## Windows
Expand Down
6 changes: 4 additions & 2 deletions src/features/liveFeature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {ReceivableMessage} from "../models/receivableMessage";
import Jimp from "jimp";
import {UiChannel} from "../models/uiChannel";
import {ChannelProcessor} from "./messaging/channelProcessor";
import {hashSync} from "bcryptjs";
import fs from "fs";
import {WritableAttachment} from "../models/writableAttachment";

Expand All @@ -22,14 +21,17 @@ export class LiveFeature {
app.get("/api/live/url", LiveEndpoints.getWebsocketEndpoint());

const server = createServer(app);
const maxPayloadSizeMb = process.env.MAX_PAYLOAD_SIZE_MB ? parseInt(process.env.MAX_PAYLOAD_SIZE_MB) : 10;
const wss = new WebSocketServer({
noServer: true
noServer: true,
maxPayload: maxPayloadSizeMb * 1024 * 1024
} as ServerOptions);

const clients = new Set<UserWebSocket>();
wss.on("connection", (ws: any, info: { user: User }) => {
ws.user = info.user;
clients.add(ws);
ws.send(JSON.stringify({type: "maxPayloadSize", size: maxPayloadSizeMb}));

ws.on("close", () => {
if (ws.user) {
Expand Down
2 changes: 1 addition & 1 deletion updateDb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ create table if not exists venel.attachments
id bigint auto_increment
primary key,
messageId bigint null,
type varchar(16) default 'file' not null,
type varchar(64) default 'file' not null,
filename text not null,
constraint attachments_ibfk_1
foreign key (messageId) references venel.messages (id)
Expand Down

0 comments on commit f807205

Please sign in to comment.