fix comments

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-11-08 20:55:38 +01:00
parent 310a867cfa
commit ed8deeec3c
11 changed files with 148 additions and 141 deletions

View File

@@ -8,12 +8,19 @@ export async function duplicateHook(
}>,
reply: FastifyReply,
) {
const isDuplicate = await isDuplicatedEvent({
ip: req.clientIp ?? '',
origin: req.headers.origin ?? '',
payload: req.body,
projectId: (req.headers['openpanel-client-id'] as string) || '',
});
const ip = req.clientIp;
const origin = req.headers.origin;
const clientId = req.headers['openpanel-client-id'];
const shouldCheck = ip && origin && clientId;
const isDuplicate = shouldCheck
? await isDuplicatedEvent({
ip,
origin,
payload: req.body,
projectId: clientId as string,
})
: false;
if (isDuplicate) {
return reply.status(200).send('Duplicate event');

View File

@@ -2,11 +2,13 @@ import { handler } from '@/controllers/track.controller';
import type { FastifyPluginCallback } from 'fastify';
import { clientHook } from '@/hooks/client.hook';
import { duplicateHook } from '@/hooks/duplicate.hook';
import { isBotHook } from '@/hooks/is-bot.hook';
const trackRouter: FastifyPluginCallback = async (fastify) => {
fastify.addHook('preHandler', clientHook);
fastify.addHook('preHandler', isBotHook);
fastify.addHook('preValidation', duplicateHook);
fastify.addHook('preHandler', clientHook);
fastify.route({
method: 'POST',

View File

@@ -137,7 +137,7 @@ export async function validateSdkRequest(
if (client.secret && clientSecret) {
const isVerified = await getCache(
`client:auth:${clientId}:${clientSecret.slice(0, 5)}`,
`client:auth:${clientId}:${Buffer.from(clientSecret).toString('base64')}`,
60 * 5,
async () => await verifyPassword(clientSecret, client.secret!),
true,