summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 16:47:51 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-08-12 16:47:51 +0200
commit675ef382aef77e126e3bbbdabe95926ad735f430 (patch)
tree69e40a94d799aaec83290cc85689a30cc3bc1276
parent:bug: :sparkles: fix templates (diff)
downloadserver-675ef382aef77e126e3bbbdabe95926ad735f430.tar.xz
:sparkles: RabbitMQ
-rw-r--r--package-lock.json14
-rw-r--r--package.json2
-rw-r--r--src/Server.ts3
-rw-r--r--src/routes/channels/#channel_id/messages/index.ts2
-rw-r--r--src/util/Event.ts7
5 files changed, 14 insertions, 14 deletions
diff --git a/package-lock.json b/package-lock.json
index d8e2d01d..ba22436a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -9,7 +9,7 @@
 			"version": "1.0.0",
 			"license": "ISC",
 			"dependencies": {
-				"@fosscord/server-util": "^1.3.49",
+				"@fosscord/server-util": "^1.3.51",
 				"@types/jest": "^26.0.22",
 				"@types/json-schema": "^7.0.7",
 				"ajv": "^8.4.0",
@@ -680,9 +680,9 @@
 			}
 		},
 		"node_modules/@fosscord/server-util": {
-			"version": "1.3.49",
-			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.49.tgz",
-			"integrity": "sha512-raWZu89X17mnNta4lAX++i5KjE8o/o4YUuP0Rnj+uFTWvvt5QQKYvCcxc7SgkezS3f5vSEcelJ/xZlJjvES4Pg==",
+			"version": "1.3.51",
+			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.51.tgz",
+			"integrity": "sha512-z7gAwj8UFTrbabtyMqb/7mhiTTpk07dKMu2ZaL4yeTPBR2Ppnkd3JqYHcrqIyMfeENgzTFoOVSjtun1aFUFDag==",
 			"dependencies": {
 				"@types/jsonwebtoken": "^8.5.0",
 				"@types/mongoose-autopopulate": "^0.10.1",
@@ -11573,9 +11573,9 @@
 			}
 		},
 		"@fosscord/server-util": {
-			"version": "1.3.49",
-			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.49.tgz",
-			"integrity": "sha512-raWZu89X17mnNta4lAX++i5KjE8o/o4YUuP0Rnj+uFTWvvt5QQKYvCcxc7SgkezS3f5vSEcelJ/xZlJjvES4Pg==",
+			"version": "1.3.51",
+			"resolved": "https://registry.npmjs.org/@fosscord/server-util/-/server-util-1.3.51.tgz",
+			"integrity": "sha512-z7gAwj8UFTrbabtyMqb/7mhiTTpk07dKMu2ZaL4yeTPBR2Ppnkd3JqYHcrqIyMfeENgzTFoOVSjtun1aFUFDag==",
 			"requires": {
 				"@types/jsonwebtoken": "^8.5.0",
 				"@types/mongoose-autopopulate": "^0.10.1",
diff --git a/package.json b/package.json
index 80e57e51..c0eacadd 100644
--- a/package.json
+++ b/package.json
@@ -33,7 +33,7 @@
 	},
 	"homepage": "https://github.com/fosscord/fosscord-api#readme",
 	"dependencies": {
-		"@fosscord/server-util": "^1.3.49",
+		"@fosscord/server-util": "^1.3.51",
 		"@types/jest": "^26.0.22",
 		"@types/json-schema": "^7.0.7",
 		"ajv": "^8.4.0",
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