MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / duplicateHook

Function duplicateHook

apps/api/src/hooks/duplicate.hook.ts:8–33  ·  view source on GitHub ↗
(
  req: FastifyRequest<{
    Body: ITrackHandlerPayload | DeprecatedPostEventPayload;
  }>,
  reply: FastifyReply
)

Source from the content-addressed store, hash-verified

6import { isDuplicatedEvent } from '@/utils/deduplicate';
7
8export async function duplicateHook(
9 req: FastifyRequest<{
10 Body: ITrackHandlerPayload | DeprecatedPostEventPayload;
11 }>,
12 reply: FastifyReply
13) {
14 const ip = req.clientIp;
15 const origin = req.headers.origin;
16 const clientId = req.headers['openpanel-client-id'];
17 const body = req?.body;
18 const isTrackPayload = getIsTrackPayload(req);
19 const isReplay = isTrackPayload && req.body.type === 'replay';
20 const shouldCheck = ip && origin && clientId && !isReplay;
21 const isDuplicate = shouldCheck
22 ? await isDuplicatedEvent({
23 ip,
24 origin,
25 payload: body,
26 projectId: clientId as string,
27 })
28 : false;
29
30 if (isDuplicate) {
31 return reply.status(200).send('Duplicate event');
32 }
33}
34
35function getIsTrackPayload(
36 req: FastifyRequest<{

Callers

nothing calls this directly

Calls 3

isDuplicatedEventFunction · 0.90
getIsTrackPayloadFunction · 0.85
sendMethod · 0.45

Tested by

no test coverage detected