summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Server.ts3
-rw-r--r--src/routes/channels/#channel_id/messages/index.ts2
-rw-r--r--src/util/Event.ts7
3 files changed, 6 insertions, 6 deletions
diff --git a/src/Server.ts b/src/Server.ts

index 69222636..3e20695a 100644 --- a/src/Server.ts +++ b/src/Server.ts
@@ -3,7 +3,7 @@ import fs from "fs"; import { Connection } from "mongoose"; import { Server, ServerOptions } from "lambert-server"; import { Authentication, CORS } from "./middlewares/"; -import { Config, db } from "@fosscord/server-util"; +import { Config, db, RabbitMQ } from "@fosscord/server-util"; import i18next from "i18next"; import i18nextMiddleware, { I18next } from "i18next-http-middleware"; import i18nextBackend from "i18next-node-fs-backend"; @@ -58,6 +58,7 @@ export class FosscordServer extends Server { await this.setupSchema(); console.log("[Database] connected"); await Config.init(); + await RabbitMQ.init(); this.app.use(CORS); this.app.use(Authentication); diff --git a/src/routes/channels/#channel_id/messages/index.ts b/src/routes/channels/#channel_id/messages/index.ts
index 59494c7e..fea4d6a4 100644 --- a/src/routes/channels/#channel_id/messages/index.ts +++ b/src/routes/channels/#channel_id/messages/index.ts
@@ -113,8 +113,6 @@ router.post("/", messageUpload.single("file"), async (req: Request, res: Respons var body = req.body as MessageCreateSchema; const attachments: Attachment[] = []; - console.log(body); - if (req.file) { try { const file = await uploadFile(`/attachments/${channel_id}`, req.file); diff --git a/src/util/Event.ts b/src/util/Event.ts
index d0b78a53..e0bcadd4 100644 --- a/src/util/Event.ts +++ b/src/util/Event.ts
@@ -1,13 +1,14 @@ -import { Config, Event, EventModel, rabbitCon, rabbitCh } from "@fosscord/server-util"; +import { Config, Event, EventModel, RabbitMQ } from "@fosscord/server-util"; export async function emitEvent(payload: Omit<Event, "created_at">) { - if (rabbitCon) { + if (RabbitMQ.connection) { const id = (payload.channel_id || payload.user_id || payload.guild_id) as string; if (!id) console.error("event doesn't contain any id", payload); const data = typeof payload.data === "object" ? JSON.stringify(payload.data) : payload.data; // use rabbitmq for event transmission + await RabbitMQ.channel?.assertQueue(id); // assertQueue isn't needed, because a queue will automatically created if it doesn't exist - const successful = rabbitCh.sendToQueue(id, Buffer.from(`${data}`), { type: payload.event }); + const successful = RabbitMQ.channel?.sendToQueue(id, Buffer.from(`${data}`), { type: payload.event }); if (!successful) throw new Error("failed to send event"); } else { // use mongodb for event transmission