forked from mtusi2026/mtusi2026lab5
lab5: базовый коммит из lab4 (abba248)
Перенесено дерево lab4 целиком: NestJS-приложение с вложениями и S3,
Dockerfile, compose.yaml, infra/{haproxy,minio}, стендовые скрипты,
scripts/lab4, evidence/lab4 и contracts/extensions.openapi.json.
Задание lab5 оставлено своим: README, REPORT, COURSE, lab.json,
contracts/{openapi,infrastructure,jobs.schema,attachment-states,examples},
tests, compose.example.yaml, .github/pull_request_template.md.
Адаптации при переносе:
- docker-проект mtusi-lab4 -> mtusi-lab5 и тег образа mtusi-messenger:lab5,
чтобы тома и контейнеры не пересекались с lab4 (scripts/stop-one.sh:
LAB_PROJECT вместо LAB4_PROJECT);
- Makefile: цели lab5 сохранены, добавлены стендовые (stand-up/down,
wait-ready, init-env, test-e2e, test-dependencies, s3-security,
consistency, bench);
- .env.example: реальные переменные приложения и стенда lab4 (без них
compose.yaml не поднимается) + блок lab5 (BROKER_URL_FILE, WORKER_*).
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { createHash } from 'node:crypto';
|
||||
|
||||
// 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.
|
||||
// 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(
|
||||
attachmentIds.length === 0
|
||||
? JSON.stringify({ text })
|
||||
: JSON.stringify({ text, attachment_ids: attachmentIds }),
|
||||
)
|
||||
.digest('hex');
|
||||
}
|
||||
Reference in New Issue
Block a user