fix comments
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user