forked from mtusi2026/mtusi2026lab4
lab4: вложения (proxy upload, download, уборщик), attachment_ids в сообщениях
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
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.
|
||||
@@ -11,8 +10,17 @@ export function messagesPath(chatId: string): string {
|
||||
|
||||
// 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 {
|
||||
// Text-only messages keep the lab3 fingerprint; the order of attachment ids
|
||||
// is significant because it is the order of attachments in the message.
|
||||
export function idempotencyFingerprint(
|
||||
text: string,
|
||||
attachmentIds: string[],
|
||||
): string {
|
||||
return createHash('sha256')
|
||||
.update(JSON.stringify({ text: input.text }))
|
||||
.update(
|
||||
attachmentIds.length === 0
|
||||
? JSON.stringify({ text })
|
||||
: JSON.stringify({ text, attachment_ids: attachmentIds }),
|
||||
)
|
||||
.digest('hex');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user