mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
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:
committed by
Tim Abbott
parent
7aa5bb233d
commit
2e38f426f4
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user