improve(api): how we check duplicate requests

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-02-28 10:03:28 +01:00
parent 7750ca117f
commit 5c6ad93ff5
8 changed files with 160 additions and 27 deletions

View File

@@ -1,21 +0,0 @@
import { getLock } from '@openpanel/redis';
import fastJsonStableHash from 'fast-json-stable-hash';
import type { FastifyReply, FastifyRequest } from 'fastify';
export async function deduplicateHook(
request: FastifyRequest,
reply: FastifyReply,
) {
if (typeof request.body === 'object') {
const locked = await getLock(
`fastify:deduplicate:${fastJsonStableHash.hash(request.body, 'md5')}`,
'1',
100,
);
if (locked) {
return;
}
}
reply.status(200).send('Duplicated event');
}