Add generic file attachments to chat messages

Messages can now carry an arbitrary file (MessageFile), parallel to the
existing MessageImage feature rather than a refactor of it. Files serve
with Content-Disposition: attachment to force a download and prevent an
uploaded HTML/SVG from executing same-origin. No content-type allowlist,
same 8MB cap as images for now (a separate size-limit redesign is tracked
as its own issue).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-15 08:02:55 -06:00
co-authored by Claude Sonnet 5
parent 89be497fdb
commit c78d7454b6
21 changed files with 697 additions and 55 deletions
+7 -7
View File
@@ -22,12 +22,12 @@ from app.services.password_service import (
)
from app.storage import (
ALLOWED_IMAGE_CONTENT_TYPES,
ImageTooLargeError,
InvalidImageError,
delete_image,
UploadTooLargeError,
delete_file,
process_image,
read_capped,
save_image,
save_file,
)
AVATAR_MAX_DIMENSION = 512
@@ -91,7 +91,7 @@ async def upload_avatar(
try:
data = await read_capped(file)
except ImageTooLargeError:
except UploadTooLargeError:
raise HTTPException(status_code=413, detail="Image exceeds 8 MB limit")
try:
@@ -102,14 +102,14 @@ async def upload_avatar(
raise HTTPException(status_code=400, detail="File is not a valid image")
previous_filename = current_user.avatar_filename
storage_filename = save_image(data, ext)
storage_filename = save_file(data, ext)
current_user.avatar_filename = storage_filename
current_user.avatar_content_type = file.content_type
await db.commit()
await db.refresh(current_user)
if previous_filename:
delete_image(previous_filename)
delete_file(previous_filename)
return current_user
@@ -126,7 +126,7 @@ async def remove_avatar(
await db.refresh(current_user)
if previous_filename:
delete_image(previous_filename)
delete_file(previous_filename)
return current_user