forked from mtusi2026/mtusi2026lab4
lab4: стенд MinIO, секреты, bootstrap, хуки; перенос приложения lab3
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
import type { CreateMessageDto } from '../dto/create-message.dto.js';
|
||||
|
||||
// Contract: ASCII [A-Za-z0-9._:-]{1,128}. Anything else (including a duplicated
|
||||
// header, which Fastify joins with ", ") is rejected as a client error.
|
||||
export const IDEMPOTENCY_KEY_PATTERN = /^[A-Za-z0-9._:-]{1,128}$/;
|
||||
|
||||
export function messagesPath(chatId: string): string {
|
||||
return `/api/v1/chats/${chatId}/messages`;
|
||||
}
|
||||
|
||||
// The fingerprint is derived from the validated payload with a fixed field
|
||||
// order, so neither JSON key order nor an absent optional field can change it.
|
||||
export function idempotencyFingerprint(input: CreateMessageDto): string {
|
||||
return createHash('sha256')
|
||||
.update(JSON.stringify({ text: input.text }))
|
||||
.digest('hex');
|
||||
}
|
||||
Reference in New Issue
Block a user