From 4b6cefc58fa546dc0e180f3e182a1d148fc1c093 Mon Sep 17 00:00:00 2001 From: anteeek Date: Tue, 8 Dec 2020 11:59:48 +0100 Subject: [PATCH] remove obsolete Sentry ; add userCount --- __tests__/setup.ts | 3 -- src/application/auth.service.ts | 8 ++++- src/application/events/events.ts | 1 + src/application/events/subscribers.ts | 10 +++++++ src/infrastructure/index.ts | 2 -- src/infrastructure/logs/sentry.ts | 42 --------------------------- src/types/infrastructure.ts | 7 ----- 7 files changed, 18 insertions(+), 55 deletions(-) delete mode 100644 src/infrastructure/logs/sentry.ts diff --git a/__tests__/setup.ts b/__tests__/setup.ts index d7f4925..fa7985e 100644 --- a/__tests__/setup.ts +++ b/__tests__/setup.ts @@ -27,9 +27,6 @@ import { inMemoryFileService } from "../src/infrastructure/filesystem"; Container.set("eventEmitter", new EventEmitter()); -Container.set("errorTracker", { - submit: jest.fn() -}) Container.set("THIS_INSTANCE_ADDRESS", "dummyhost:202020"); diff --git a/src/application/auth.service.ts b/src/application/auth.service.ts index 053dde0..085d07a 100644 --- a/src/application/auth.service.ts +++ b/src/application/auth.service.ts @@ -18,18 +18,22 @@ | along with this program. If not, see . */ import jwt from "jsonwebtoken"; +import { EventEmitter } from "events"; import { Container, Service, Inject } from "typedi"; + import { TUserCredentials, TAdminCredentials, ITokenClaims, TUserTokenClaims, TAdminTokenClaims } from "../types/auth"; import { AppError } from "../infrastructure/utils"; import { TChatroomRepository } from "../types/infrastructure"; +import events from "./events/events"; @Service() export default class AuthService { constructor( - @Inject("chatroomRepository") private chatroomRepository: TChatroomRepository + @Inject("chatroomRepository") private chatroomRepository: TChatroomRepository, + @Inject("eventEmitter") private eventEmitter: EventEmitter ) {}; async login({ slug, ...credentials }: TUserCredentials) { @@ -56,6 +60,8 @@ export default class AuthService { await this.chatroomRepository.persist(chatroom); + this.eventEmitter.emit(events.USER_JOINED_CHATROOM); + return await signToken({ slug, name: "@"+credentials.name, diff --git a/src/application/events/events.ts b/src/application/events/events.ts index 28ffdb7..13475f2 100644 --- a/src/application/events/events.ts +++ b/src/application/events/events.ts @@ -19,4 +19,5 @@ */ export default { NEW_CHATROOM: "chatrooms:new", + USER_JOINED_CHATROOM: "chatrooms:user-joined" } \ No newline at end of file diff --git a/src/application/events/subscribers.ts b/src/application/events/subscribers.ts index 954660e..a7a7e01 100644 --- a/src/application/events/subscribers.ts +++ b/src/application/events/subscribers.ts @@ -38,4 +38,14 @@ export default () => { keyValueStore.setItem("CHATROOM_COUNT", chatroomCount + 1); }); + emitter.on(events.USER_JOINED_CHATROOM, async () => { + + let userCount = keyValueStore.getItem("USER_COUNT"); + + if((typeof userCount) !== "number") + userCount = 0; + + keyValueStore.setItem("USER_COUNT", userCount + 1); + }) + } \ No newline at end of file diff --git a/src/infrastructure/index.ts b/src/infrastructure/index.ts index 6f6b044..63976c4 100644 --- a/src/infrastructure/index.ts +++ b/src/infrastructure/index.ts @@ -25,7 +25,6 @@ import config from "./config"; import Logger from "./logs/logger"; import eventEmitter from "./emitter"; import jobScheduler from "./jobs"; -import errorTracker from "./logs/sentry"; import { alligatorFetcher } from "./fetcher"; @@ -57,7 +56,6 @@ Container.set("THIS_INSTANCE_ADDRESS", THIS_INSTANCE_ADDRESS); Container.set("logger", Logger); Container.set("eventEmitter", eventEmitter); Container.set("jobScheduler", jobScheduler); -Container.set("errorTracker", errorTracker); Container.set("fileService", memoryMode ? inMemoryFileService : fileService); Container.set("keyValueStore", keyValueStore); diff --git a/src/infrastructure/logs/sentry.ts b/src/infrastructure/logs/sentry.ts deleted file mode 100644 index cc99149..0000000 --- a/src/infrastructure/logs/sentry.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -| For alternative licensing arrangements contact us at freedom@chatcola.com -|-------------------------------------------------------------------------------- -| This file is part of chatcola.com server -| Copyright (C) 2020 Antoni Papiewski & Milan Kazarka -| -| This program is free software: you can redistribute it and/or modify -| it under the terms of the GNU Affero General Public License as published by -| the Free Software Foundation, either version 3 of the License, or -| (at your option) any later version. -| -| This program is distributed in the hope that it will be useful, -| but WITHOUT ANY WARRANTY; without even the implied warranty of -| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -| GNU Affero General Public License for more details. -| -| You should have received a copy of the GNU Affero General Public License -| along with this program. If not, see . -*/ -import * as Sentry from '@sentry/node'; -import { Dedupe as DedupeIntegration } from '@sentry/integrations'; - -import config from "../config"; -import Logger from "./logger"; -import { TErrorTracker } from 'types/infrastructure'; - -if(config.should_report_errors) { - Sentry.init({ - dsn: "https://ebb3eb5b441349d0863fcd9c586d8260@o386888.ingest.sentry.io/5258873", - integrations: [ - new DedupeIntegration(), - ], - onFatalError: (error: any) => Logger.error(error) - }); -} - -export default { - submit: (err: any) => { - if(config.should_report_errors) - Sentry.captureException(err); - } -} as TErrorTracker; \ No newline at end of file diff --git a/src/types/infrastructure.ts b/src/types/infrastructure.ts index 1c9dac1..74685b5 100644 --- a/src/types/infrastructure.ts +++ b/src/types/infrastructure.ts @@ -120,13 +120,6 @@ export type TAlligatorWsConnector = { }; } -/** / - * /------------------------------------------ -*/ - -export type TErrorTracker = { - submit: (err: any) => Promise; -} /** / * /------------------------------------------ */