diff --git a/api/package.json b/api/package.json
index 9701e12d..ab41b675 100644
--- a/api/package.json
+++ b/api/package.json
@@ -65,6 +65,8 @@
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@fosscord/util": "file:../util",
+ "@sentry/node": "^6.16.1",
+ "@sentry/tracing": "^6.16.1",
"ajv": "8.6.2",
"ajv-formats": "^2.1.1",
"amqplib": "^0.8.0",
diff --git a/api/src/routes/channels/#channel_id/messages/index.ts b/api/src/routes/channels/#channel_id/messages/index.ts
index d3c0a409..b2fb615c 100644
--- a/api/src/routes/channels/#channel_id/messages/index.ts
+++ b/api/src/routes/channels/#channel_id/messages/index.ts
@@ -107,7 +107,7 @@ router.get("/", async (req: Request, res: Response) => {
const endpoint = Config.get().cdn.endpointPublic;
return res.json(
- messages.map((x) => {
+ messages.map((x: any) => {
(x.reactions || []).forEach((x: any) => {
// @ts-ignore
if ((x.user_ids || []).includes(req.user_id)) x.me = true;
@@ -116,10 +116,10 @@ router.get("/", async (req: Request, res: Response) => {
});
// @ts-ignore
if (!x.author) x.author = { discriminator: "0000", username: "Deleted User", public_flags: "0", avatar: null };
- x.attachments?.forEach((x) => {
+ x.attachments?.forEach((y: any) => {
// dynamically set attachment proxy_url in case the endpoint changed
- const uri = x.proxy_url.startsWith("http") ? x.proxy_url : `https://example.org${x.proxy_url}`;
- x.proxy_url = `${endpoint == null ? "" : endpoint}${new URL(uri).pathname}`;
+ const uri = y.proxy_url.startsWith("http") ? y.proxy_url : `https://example.org${y.proxy_url}`;
+ y.proxy_url = `${endpoint == null ? "" : endpoint}${new URL(uri).pathname}`;
});
return x;
diff --git a/bundle/package.json b/bundle/package.json
index 17d59a25..97066bd8 100644
--- a/bundle/package.json
+++ b/bundle/package.json
@@ -59,6 +59,12 @@
"@aws-sdk/node-http-handler": "^3.36.0",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
+ "@fosscord/api": "file:../api",
+ "@fosscord/cdn": "file:../cdn",
+ "@fosscord/gateway": "file:../gateway",
+ "@fosscord/util": "file:../util",
+ "@sentry/node": "^6.16.1",
+ "@sentry/tracing": "^6.16.1",
"ajv": "8.6.2",
"ajv-formats": "^2.1.1",
"amqplib": "^0.8.0",
@@ -95,6 +101,7 @@
"reflect-metadata": "^0.1.13",
"sqlite3": "^5.0.2",
"supertest": "^6.1.6",
+ "tslib": "^2.3.1",
"typeorm": "^0.2.37",
"typescript": "^4.1.2",
"typescript-json-schema": "^0.50.1",
diff --git a/bundle/src/Server.ts b/bundle/src/Server.ts
index e461ec5f..d07a6ce0 100644
--- a/bundle/src/Server.ts
+++ b/bundle/src/Server.ts
@@ -8,6 +8,8 @@ import { CDNServer } from "@fosscord/cdn";
import express from "express";
import { green, bold } from "nanocolors";
import { Config, initDatabase } from "@fosscord/util";
+import * as Sentry from "@sentry/node";
+import * as Tracing from "@sentry/tracing";
const app = express();
const server = http.createServer();
@@ -56,7 +58,31 @@ async function main() {
// },
} as any);
+ //Sentry
+ if (Config.get().sentry.enabled) {
+ console.log(
+ "[Bundle] You are using Sentry! This may slightly impact performance on large loads!"
+ );
+ Sentry.init({
+ dsn: Config.get().sentry.endpoint,
+ integrations: [
+ new Sentry.Integrations.Http({ tracing: true }),
+ new Tracing.Integrations.Express({ app }),
+ ],
+ tracesSampleRate: Config.get().sentry.traceSampleRate,
+ });
+
+ app.use(Sentry.Handlers.requestHandler());
+ app.use(Sentry.Handlers.tracingHandler());
+ }
await Promise.all([api.start(), cdn.start(), gateway.start()]);
+ if (Config.get().sentry.enabled) {
+ app.use(Sentry.Handlers.errorHandler());
+ app.use(function onError(err: any, req: any, res: any, next: any) {
+ res.statusCode = 500;
+ res.end(res.sentry + "\n");
+ });
+ }
console.log(`[Server] ${green(`listening on port ${bold(port)}`)}`);
}
diff --git a/bundle/tsconfig.json b/bundle/tsconfig.json
index 58c61132..2257b4ab 100644
--- a/bundle/tsconfig.json
+++ b/bundle/tsconfig.json
@@ -45,7 +45,7 @@
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
+ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
"types": [
@@ -79,6 +79,8 @@
"@fosscord/cdn": ["cdn/src/index"],
"@fosscord/util": ["util/src/index"]
},
- "plugins": [{ "transform": "@zerollup/ts-transform-paths" }]
+ "plugins": [{ "transform": "@zerollup/ts-transform-paths" }],
+ "noEmitHelpers": true,
+ "importHelpers": true
}
}
diff --git a/util/package.json b/util/package.json
index 0b8423a5..e93eeab4 100644
--- a/util/package.json
+++ b/util/package.json
@@ -39,7 +39,6 @@
},
"dependencies": {
"amqplib": "^0.8.0",
- "better-sqlite3": "^7.4.3",
"form-data": "^4.0.0",
"jsonwebtoken": "^8.5.1",
"lambert-server": "^1.2.12",
diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts
index d20078e5..aabca016 100644
--- a/util/src/entities/BaseClass.ts
+++ b/util/src/entities/BaseClass.ts
@@ -52,12 +52,12 @@ export class BaseClassWithoutId extends BaseEntity {
static increment<T extends BaseClass>(conditions: FindConditions<T>, propertyPath: string, value: number | string) {
const repository = this.getRepository();
- return repository.increment(conditions, propertyPath, value);
+ return repository.increment(conditions as T, propertyPath, value);
}
static decrement<T extends BaseClass>(conditions: FindConditions<T>, propertyPath: string, value: number | string) {
const repository = this.getRepository();
- return repository.decrement(conditions, propertyPath, value);
+ return repository.decrement(conditions as T, propertyPath, value);
}
}
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts
index bd2e5a58..4036b5d6 100644
--- a/util/src/entities/Channel.ts
+++ b/util/src/entities/Channel.ts
@@ -203,7 +203,7 @@ export class Channel extends BaseClass {
static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) {
recipients = recipients.unique().filter((x) => x !== creator_user_id);
- const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })), select: ["id"] });
+ const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })) });
// TODO: check config for max number of recipients
if (otherRecipientsUsers.length !== recipients.length) {
diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts
index 2d003c99..31384412 100644
--- a/util/src/entities/Config.ts
+++ b/util/src/entities/Config.ts
@@ -188,6 +188,11 @@ export interface ConfigValue {
},
metrics: {
timeout: number;
+ },
+ sentry: {
+ enabled: boolean;
+ endpoint: string;
+ traceSampleRate: number;
}
}
@@ -377,5 +382,10 @@ export const DefaultConfigOptions: ConfigValue = {
},
metrics: {
timeout: 30000
+ },
+ sentry: {
+ enabled: false,
+ endpoint: "",
+ traceSampleRate: 1.0
}
};
|