Private
Public Access
Add image uploads in chat messages (Gitea issue #10)
Images live on the app server's local disk (uploads/), served through an authenticated, room-membership-gated endpoint since rooms can be private. Uploads are streamed with a byte-count cap, validated as genuine decodable images with Pillow (not just a spoofed Content-Type), and downscaled to 2000px on the longer side (except GIF, to preserve animation). Backend: MessageImage model + nullable Message.content/image_id with a content-or-image CheckConstraint, upload/serve endpoints in rooms.py, WS message envelope gains image_id, push notification body says "sent an image" for image-only messages. Frontend: Composer gets an attach button with upload progress and a thumbnail chip; MessageList renders images inline with a click-to-zoom ImageLightbox.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
"""message images
|
||||
|
||||
Revision ID: c610bdb04567
|
||||
Revises: 3350c67553ad
|
||||
Create Date: 2026-08-14 12:00:58.698701
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'c610bdb04567'
|
||||
down_revision: Union[str, Sequence[str], None] = '3350c67553ad'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('message_images',
|
||||
sa.Column('id', sa.Uuid(), nullable=False),
|
||||
sa.Column('room_id', sa.Uuid(), nullable=False),
|
||||
sa.Column('uploaded_by', sa.Uuid(), nullable=False),
|
||||
sa.Column('storage_filename', sa.String(length=64), nullable=False),
|
||||
sa.Column('content_type', sa.String(length=50), nullable=False),
|
||||
sa.Column('size_bytes', sa.BigInteger(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['room_id'], ['rooms.id'], ),
|
||||
sa.ForeignKeyConstraint(['uploaded_by'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_message_images_room_id'), 'message_images', ['room_id'], unique=False)
|
||||
op.add_column('messages', sa.Column('image_id', sa.Uuid(), nullable=True))
|
||||
op.alter_column('messages', 'content',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=True)
|
||||
op.create_foreign_key('messages_image_id_fkey', 'messages', 'message_images', ['image_id'], ['id'])
|
||||
op.create_check_constraint('messages_content_or_image_required', 'messages', 'content IS NOT NULL OR image_id IS NOT NULL')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint('messages_content_or_image_required', 'messages', type_='check')
|
||||
op.drop_constraint('messages_image_id_fkey', 'messages', type_='foreignkey')
|
||||
op.alter_column('messages', 'content',
|
||||
existing_type=sa.TEXT(),
|
||||
nullable=False)
|
||||
op.drop_column('messages', 'image_id')
|
||||
op.drop_index(op.f('ix_message_images_room_id'), table_name='message_images')
|
||||
op.drop_table('message_images')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user