📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
installed ioredis types & fixed some possible issues
Blue Mousef0d4afe3766d
diff --git a/package.json b/package.jsonindex 01118e28e..3b788bdfb 100644--- a/package.json+++ b/package.json@@ -63,6 +63,7 @@"@nestjs/testing": "^7.6.18","@types/bcrypt": "^3.0.0","@types/express": "^4.17.11",+ "@types/ioredis": "^4.28.3","@types/jest": "^27.0.2","@types/node": "^14.14.31","@types/nodemailer": "^6.4.1",diff --git a/src/analytics/analytics.controller.ts b/src/analytics/analytics.controller.tsindex c8f2c37b7..9b1eae6f4 100644--- a/src/analytics/analytics.controller.ts+++ b/src/analytics/analytics.controller.ts@@ -17,9 +17,7 @@ import { ApiTags } from '@nestjs/swagger'import * as UAParser from 'ua-parser-js'import { AnalyticsService, getSessionKey } from './analytics.service'-import { UserType } from '../user/entities/user.entity'import { CurrentUserId } from '../common/decorators/current-user-id.decorator'-import { Roles } from '../common/decorators/roles.decorator'import { RolesGuard } from 'src/common/guards/roles.guard'import { PageviewsDTO } from './dto/pageviews.dto'import { EventsDTO } from './dto/events.dto'@@ -155,6 +153,7 @@ export class AnalyticsController {for (let i = 0; i < pidsSize; ++i) {const currentPID = pidsArray[i]+ // @ts-ignoreconst keysAmout = await redis.countKeysByPattern(`hb:${currentPID}:*`)result[currentPID] = keysAmout}diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.tsindex ddd563a9b..f4d9805ef 100644--- a/src/analytics/analytics.service.ts+++ b/src/analytics/analytics.service.ts@@ -38,7 +38,7 @@ export class AnalyticsService {async getRedisProject(pid: string): Promise<Project | null> {const pidKey = getRedisProjectKey(pid)- let project = await redis.get(pidKey)+ let project: string | Project = await redis.get(pidKey)if (_isEmpty(project)) {if (isSelfhosted) {@@ -60,6 +60,7 @@ export class AnalyticsService {}}+ // @ts-ignorereturn project}@@ -102,13 +103,15 @@ export class AnalyticsService {await redis.set(countKey, `${pageviews}`, 'EX', redisProjectCountCacheTimeout)} else {try {+ // @ts-ignorecount = Number(count)} catch (e) {console.error(e)throw new InternalServerErrorException('Error while processing project')}}-++ // @ts-ignorereturn count}diff --git a/src/common/constants.ts b/src/common/constants.tsindex 45ff646e5..82bdd5506 100644--- a/src/common/constants.ts+++ b/src/common/constants.ts@@ -8,9 +8,7 @@ import * as _round from 'lodash/round'require('dotenv').config()-const redis = new Redis({- port: process.env.REDIS_PORT,- host: process.env.REDIS_HOST,+const redis = new Redis(_toNumber(process.env.REDIS_PORT), process.env.REDIS_HOST, {password: process.env.REDIS_PASSWORD,})diff --git a/src/common/utils.ts b/src/common/utils.tsindex 9ab3261f9..b29035902 100644--- a/src/common/utils.ts+++ b/src/common/utils.ts@@ -37,10 +37,9 @@ const getRandomTip = (language: string = 'en'): string => {}// 'action' is used as a salt to differ rate limiting routes-const checkRateLimit = async (ip: string, action: string, reqAmount = RATE_LIMIT_REQUESTS_AMOUNT, reqTimeout = RATE_LIMIT_TIMEOUT): Promise<void> => {+const checkRateLimit = async (ip: string, action: string, reqAmount: number = RATE_LIMIT_REQUESTS_AMOUNT, reqTimeout: number = RATE_LIMIT_TIMEOUT): Promise<void> => {const rlHash = _getRateLimitHash(ip, action)- let rlCount = await redis.get(rlHash)- rlCount = _toNumber(rlCount) || 0+ let rlCount: number = _toNumber(await redis.get(rlHash)) || 0if (rlCount >= reqAmount) {throw new ForbiddenException('Too many requests, please try again later')