From 93c97000497ceccfca52d51c2c475fdf81e1cca8 Mon Sep 17 00:00:00 2001 From: Jasmin Date: Sun, 17 Nov 2024 15:28:36 +0100 Subject: [PATCH] feat: remove plausible service --- .env.example | 1 - src/app.module.ts | 2 -- src/plausible/plausible.controller.ts | 31 ------------------ src/plausible/plausible.module.ts | 11 ------- src/plausible/plausible.service.ts | 46 --------------------------- 5 files changed, 91 deletions(-) delete mode 100644 src/plausible/plausible.controller.ts delete mode 100644 src/plausible/plausible.module.ts delete mode 100644 src/plausible/plausible.service.ts diff --git a/.env.example b/.env.example index eb18a34..eb17014 100644 --- a/.env.example +++ b/.env.example @@ -18,4 +18,3 @@ INVENTORY_CACHETIME=300000 WITCH_IT_ENDPOINT= WITCH_IT_AUTH_TOKEN= -PLAUSIBLE_HOST= diff --git a/src/app.module.ts b/src/app.module.ts index 96da2ba..7887827 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -29,7 +29,6 @@ import { StatsModule } from './stats/stats.module'; import { QuestsModule } from './quests/quests.module'; import { UserQuest } from './quests/entities/userQuest.entity'; import { Quest } from './quests/entities/quest.entity'; -import { PlausibleModule } from './plausible/plausible.module'; import { WitchItModule } from 'src/witchit/witchit.module'; @Module({ @@ -73,7 +72,6 @@ import { WitchItModule } from 'src/witchit/witchit.module'; SearchModule, StatsModule, QuestsModule, - PlausibleModule, ], controllers: [], providers: [], diff --git a/src/plausible/plausible.controller.ts b/src/plausible/plausible.controller.ts deleted file mode 100644 index b61563a..0000000 --- a/src/plausible/plausible.controller.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { - CacheInterceptor, - CacheTTL, - Controller, - Get, - HttpCode, - Post, - Req, - Res, - UseInterceptors, -} from '@nestjs/common'; -import { PlausibleService } from './plausible.service'; -import { Request, Response } from 'express'; - -@Controller('blue') -export class PlausibleController { - constructor(private _plausibleService: PlausibleService) {} - - @Get('script.js') - @UseInterceptors(CacheInterceptor) - @CacheTTL(1000 * 60 * 60 * 24) - getScript(@Res() response: Response) { - return this._plausibleService.getScript(response); - } - - @Post('event') - @HttpCode(202) - postEvent(@Req() request: Request) { - return this._plausibleService.postEvent(request); - } -} diff --git a/src/plausible/plausible.module.ts b/src/plausible/plausible.module.ts deleted file mode 100644 index 3c1a481..0000000 --- a/src/plausible/plausible.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { HttpModule } from '@nestjs/axios'; -import { CacheModule, Module } from '@nestjs/common'; -import { PlausibleController } from './plausible.controller'; -import { PlausibleService } from './plausible.service'; - -@Module({ - imports: [CacheModule.register(), HttpModule], - controllers: [PlausibleController], - providers: [PlausibleService], -}) -export class PlausibleModule {} diff --git a/src/plausible/plausible.service.ts b/src/plausible/plausible.service.ts deleted file mode 100644 index 47db0a2..0000000 --- a/src/plausible/plausible.service.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { HttpService } from '@nestjs/axios'; -import { Injectable } from '@nestjs/common'; -import { Request, Response } from 'express'; -import * as rawbody from 'raw-body'; - -@Injectable() -export class PlausibleService { - constructor(private readonly httpService: HttpService) {} - - public async getScript(response: Response) { - const script = await this.httpService.axiosRef.get( - `${process.env.PLAUSIBLE_HOST}/js/script.js`, - ); - response.setHeader('Content-Type', 'text/javascript'); - response.send(script.data); - } - - public async postEvent(request: Request) { - const forwardedHeaders = { - 'User-Agent': request.headers['user-agent'] as string, - 'Content-Type': 'application/json', - 'X-Forwarded-Proto': request.headers['cf-visitor'] - ? JSON.parse(request.headers['cf-visitor'] as string).scheme - : request.protocol, - 'cf-connecting-ip': request.headers['cf-connecting-ip'] - ? (request.headers['cf-connecting-ip'] as string) - : request.ip, - 'X-Forwarded-Host': request.hostname, - }; - - let body = request.body; - - if (request.readable) { - const raw = await rawbody(request); - body = raw.toString().trim(); - } - - await this.httpService.axiosRef.post( - `${process.env.PLAUSIBLE_HOST}/api/event`, - body, - { - headers: forwardedHeaders, - }, - ); - } -}