feat: add image attachments to messages
- upload, metadata and download endpoints for PNG/JPEG attachments:
limits before reading and decompression, type by content,
structural integrity check without decoding pixels, safe filename
- write order: pending row with object key -> PUT to S3 -> ready;
per-step DB sessions so no pool connection is held during transfers
- attachment_ids in messages (validation, idempotency hash, history);
whitespace-only text allowed with an attachment (teacher, 2026-10-20)
- migration: attachments and message_attachments tables, text length
CHECK relaxed with NOT VALID
- student tests, fault checks and driver commands for attachments;
rollout profile starts from e1161f7 and checks the commit first
- sync attachments deltas into main specs; rules, AGENTS.md, PLAN.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,25 @@ paths:
|
||||
|
||||
Порог `expired_before`, решение «повтор или 409» и commit — в
|
||||
сервисе. Ключ в исключения и логи не попадает.
|
||||
- Repo вложений (лаба 4, design change `attachments`, решения 3, 4, 8):
|
||||
- `attachment.py`: `insert_attachment`, `mark_ready` (`UPDATE … WHERE
|
||||
status = 'pending' RETURNING`, `None` — строки `pending` нет),
|
||||
`get_attachment`, `get_attachments` (до 10 строк по первичному
|
||||
ключу). Значения `content_type` и `status` — `.value` enum на
|
||||
записи и enum в DTO на чтении;
|
||||
- `attachment_object.py` — repo над S3, как `chat_cache.py` над
|
||||
Valkey: первый параметр `storage: ObjectStorage`, один вызов на
|
||||
функцию. `original_key` собирает `<namespace>/attachments/<id>/
|
||||
original` (namespace — имя базы, `filename` не входит),
|
||||
`put_original`, `open_original` (контекст объекта). Ключ хранится в
|
||||
строке и при чтении берётся из неё, не вычисляется заново;
|
||||
- `message.py`: `MESSAGE_COLUMNS` с коррелированным подзапросом
|
||||
`ARRAY(SELECT attachment_id … ORDER BY position)` — одно выражение на
|
||||
страницу и на сохранённый результат ключа; план — `SubPlan` по
|
||||
`pk_message_attachments` на строку страницы, индекс истории прежний.
|
||||
DTO — `to_message_dto` (массив → кортеж). Вставка сообщения
|
||||
перечисляет свои колонки, связи — `insert_message_attachments` одной
|
||||
многострочной вставкой с `position`.
|
||||
- Repo кэша (`chat_cache.py`) — то же правило над Valkey: первый
|
||||
параметр `cache: Cache`, одна команда на функцию, ключ и формат
|
||||
значения (JSON ↔ DTO) живут здесь. Ключ включает
|
||||
|
||||
Reference in New Issue
Block a user