upload: Rename "upload_image_to_s3"; it is not only for images.

This commit is contained in:
Alex Vandiver 2024-08-29 20:49:28 +00:00 committed by Tim Abbott
parent c8c480baef
commit ca72e756eb
2 changed files with 10 additions and 10 deletions

View File

@ -12,7 +12,7 @@ from zerver.lib.avatar_hash import user_avatar_path
from zerver.lib.mime_types import guess_type from zerver.lib.mime_types import guess_type
from zerver.lib.thumbnail import BadImageError from zerver.lib.thumbnail import BadImageError
from zerver.lib.upload import upload_emoji_image, write_avatar_images from zerver.lib.upload import upload_emoji_image, write_avatar_images
from zerver.lib.upload.s3 import S3UploadBackend, upload_image_to_s3 from zerver.lib.upload.s3 import S3UploadBackend, upload_content_to_s3
from zerver.models import Attachment, RealmEmoji, UserProfile from zerver.models import Attachment, RealmEmoji, UserProfile
s3backend = S3UploadBackend() s3backend = S3UploadBackend()
@ -74,7 +74,7 @@ def _transfer_message_files_to_s3(attachment: Attachment) -> None:
try: try:
with open(file_path, "rb") as f: with open(file_path, "rb") as f:
guessed_type = guess_type(attachment.file_name)[0] guessed_type = guess_type(attachment.file_name)[0]
upload_image_to_s3( upload_content_to_s3(
s3backend.uploads_bucket, s3backend.uploads_bucket,
attachment.path_id, attachment.path_id,
guessed_type, guessed_type,

View File

@ -60,7 +60,7 @@ def get_bucket(bucket_name: str, authed: bool = True) -> Bucket:
).Bucket(bucket_name) ).Bucket(bucket_name)
def upload_image_to_s3( def upload_content_to_s3(
bucket: Bucket, bucket: Bucket,
file_name: str, file_name: str,
content_type: str | None, content_type: str | None,
@ -215,7 +215,7 @@ class S3UploadBackend(ZulipUploadBackend):
file_data: bytes, file_data: bytes,
user_profile: UserProfile | None, user_profile: UserProfile | None,
) -> None: ) -> None:
upload_image_to_s3( upload_content_to_s3(
self.uploads_bucket, self.uploads_bucket,
path_id, path_id,
content_type, content_type,
@ -279,7 +279,7 @@ class S3UploadBackend(ZulipUploadBackend):
future: bool = True, future: bool = True,
) -> None: ) -> None:
extra_metadata = {"avatar_version": str(user_profile.avatar_version + (1 if future else 0))} extra_metadata = {"avatar_version": str(user_profile.avatar_version + (1 if future else 0))}
upload_image_to_s3( upload_content_to_s3(
self.avatar_bucket, self.avatar_bucket,
file_path, file_path,
content_type, content_type,
@ -307,7 +307,7 @@ class S3UploadBackend(ZulipUploadBackend):
s3_file_name = os.path.join(self.realm_avatar_and_logo_path(user_profile.realm), "icon") s3_file_name = os.path.join(self.realm_avatar_and_logo_path(user_profile.realm), "icon")
image_data = icon_file.read() image_data = icon_file.read()
upload_image_to_s3( upload_content_to_s3(
self.avatar_bucket, self.avatar_bucket,
s3_file_name + ".original", s3_file_name + ".original",
content_type, content_type,
@ -316,7 +316,7 @@ class S3UploadBackend(ZulipUploadBackend):
) )
resized_data = resize_avatar(image_data) resized_data = resize_avatar(image_data)
upload_image_to_s3( upload_content_to_s3(
self.avatar_bucket, self.avatar_bucket,
s3_file_name + ".png", s3_file_name + ".png",
"image/png", "image/png",
@ -346,7 +346,7 @@ class S3UploadBackend(ZulipUploadBackend):
s3_file_name = os.path.join(self.realm_avatar_and_logo_path(user_profile.realm), basename) s3_file_name = os.path.join(self.realm_avatar_and_logo_path(user_profile.realm), basename)
image_data = logo_file.read() image_data = logo_file.read()
upload_image_to_s3( upload_content_to_s3(
self.avatar_bucket, self.avatar_bucket,
s3_file_name + ".original", s3_file_name + ".original",
content_type, content_type,
@ -355,7 +355,7 @@ class S3UploadBackend(ZulipUploadBackend):
) )
resized_data = resize_logo(image_data) resized_data = resize_logo(image_data)
upload_image_to_s3( upload_content_to_s3(
self.avatar_bucket, self.avatar_bucket,
s3_file_name + ".png", s3_file_name + ".png",
"image/png", "image/png",
@ -383,7 +383,7 @@ class S3UploadBackend(ZulipUploadBackend):
def upload_single_emoji_image( def upload_single_emoji_image(
self, path: str, content_type: str | None, user_profile: UserProfile, image_data: bytes self, path: str, content_type: str | None, user_profile: UserProfile, image_data: bytes
) -> None: ) -> None:
upload_image_to_s3( upload_content_to_s3(
self.avatar_bucket, self.avatar_bucket,
path, path,
content_type, content_type,