lab4: вложения (proxy upload, download, уборщик), attachment_ids в сообщениях

This commit is contained in:
2026-10-22 22:28:54 +03:00
parent ec4e9fb608
commit 6fcc623447
23 changed files with 959 additions and 106 deletions
+11 -3
View File
@@ -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');
}