upload: Generate thumbnails when images are uploaded.

A new table is created to track which path_id attachments are images,
and for those their metadata, and which thumbnails have been created.
Using path_id as the effective primary key lets us ignore if the
attachment is archived or not, saving some foreign key messes.

A new worker is added to observe events when rows are added to this
table, and to generate and store thumbnails for those images in
differing sizes and formats.
This commit is contained in:
Alex Vandiver
2024-06-20 21:58:27 +00:00
committed by Tim Abbott
parent 7aa5bb233d
commit 2e38f426f4
21 changed files with 788 additions and 50 deletions

View File

@@ -25,6 +25,7 @@ from zerver.models.messages import ArchivedSubMessage as ArchivedSubMessage
from zerver.models.messages import ArchivedUserMessage as ArchivedUserMessage
from zerver.models.messages import ArchiveTransaction as ArchiveTransaction
from zerver.models.messages import Attachment as Attachment
from zerver.models.messages import ImageAttachment as ImageAttachment
from zerver.models.messages import Message as Message
from zerver.models.messages import OnboardingUserMessage as OnboardingUserMessage
from zerver.models.messages import Reaction as Reaction

View File

@@ -665,6 +665,18 @@ class ArchivedUserMessage(AbstractUserMessage):
return f"{recipient_string} / {self.user_profile.email} ({self.flags_list()})"
class ImageAttachment(models.Model):
realm = models.ForeignKey(Realm, on_delete=CASCADE)
path_id = models.TextField(db_index=True, unique=True)
original_width_px = models.IntegerField()
original_height_px = models.IntegerField()
frames = models.IntegerField()
# Contains a list of zerver.lib.thumbnail.StoredThumbnailFormat objects, serialized
thumbnail_metadata = models.JSONField(default=list, null=False)
class AbstractAttachment(models.Model):
file_name = models.TextField(db_index=True)