Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
upload: Rename attachment_vips_source, as it's not just for vips_source.
Alex Vandiver085d13787127
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.pyindex 657011c5daf..46794f086f5 100644--- a/zerver/lib/upload/__init__.py+++ b/zerver/lib/upload/__init__.py@@ -249,8 +249,8 @@ def upload_message_attachment_from_request()-def attachment_vips_source(path_id: str) -> StreamingSourceWithSize:- return upload_backend.attachment_vips_source(path_id)+def attachment_source(path_id: str) -> StreamingSourceWithSize:+ return upload_backend.attachment_source(path_id)def save_attachment_contents(path_id: str, filehandle: IO[bytes]) -> None:diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.pyindex f41b186b6a2..7bf22450718 100644--- a/zerver/lib/upload/base.py+++ b/zerver/lib/upload/base.py@@ -43,7 +43,7 @@ class ZulipUploadBackend:def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:raise NotImplementedError- def attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:+ def attachment_source(self, path_id: str) -> StreamingSourceWithSize:raise NotImplementedErrordef delete_message_attachment(self, path_id: str) -> bool:diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.pyindex e4caaff6744..1da384bc6bf 100644--- a/zerver/lib/upload/local.py+++ b/zerver/lib/upload/local.py@@ -103,7 +103,7 @@ class LocalUploadBackend(ZulipUploadBackend):filehandle.write(chunk)@override- def attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:+ def attachment_source(self, path_id: str) -> StreamingSourceWithSize:file_path = os.path.join(assert_is_not_none(settings.LOCAL_UPLOADS_DIR), "files", path_id)assert_is_local_storage_path("files", file_path)vips_source = pyvips.Source.new_from_file(file_path)diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.pyindex 02b98d70ade..953bad5ce66 100644--- a/zerver/lib/upload/s3.py+++ b/zerver/lib/upload/s3.py@@ -273,7 +273,7 @@ class S3UploadBackend(ZulipUploadBackend):filehandle.write(chunk)@override- def attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:+ def attachment_source(self, path_id: str) -> StreamingSourceWithSize:metadata = self.uploads_bucket.Object(path_id).get()def s3_read(streamingbody: StreamingBody, size: int) -> bytes:diff --git a/zerver/tests/test_thumbnail.py b/zerver/tests/test_thumbnail.pyindex eaab55f2025..e39998dbca3 100644--- a/zerver/tests/test_thumbnail.py+++ b/zerver/tests/test_thumbnail.py@@ -29,7 +29,7 @@ from zerver.lib.thumbnail import ()from zerver.lib.upload import (all_message_attachments,- attachment_vips_source,+ attachment_source,create_attachment,save_attachment_contents,upload_backend,@@ -746,7 +746,7 @@ class TestStoreThumbnail(ZulipTestCase):upload_backend.upload_message_attachment(path_id, "img.png", "image/png", read_test_image_file("img.png"), hamlet)- source = attachment_vips_source(path_id)+ source = attachment_source(path_id)create_attachment("img.png", path_id, "image/png", source, hamlet, hamlet.realm)self.assertTrue(ImageAttachment.objects.filter(path_id=path_id).exists())diff --git a/zerver/tests/test_upload_local.py b/zerver/tests/test_upload_local.pyindex 2311e07b308..b67fc713f14 100644--- a/zerver/tests/test_upload_local.py+++ b/zerver/tests/test_upload_local.py@@ -13,7 +13,7 @@ from zerver.lib.test_helpers import get_test_image_file, read_test_image_filefrom zerver.lib.thumbnail import DEFAULT_EMOJI_SIZE, MEDIUM_AVATAR_SIZE, resize_avatarfrom zerver.lib.upload import (all_message_attachments,- attachment_vips_source,+ attachment_source,delete_export_tarball,delete_message_attachment,delete_message_attachments,@@ -54,14 +54,14 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):save_attachment_contents(path_id, output)self.assertEqual(output.getvalue(), b"zulip!")- def test_attachment_vips_source(self) -> None:+ def test_attachment_source(self) -> None:user_profile = self.example_user("hamlet")url = upload_message_attachment("img.png", "image/png", read_test_image_file("img.png"), user_profile)[0]path_id = re.sub(r"/user_uploads/", "", url)- source = attachment_vips_source(path_id)+ source = attachment_source(path_id)self.assertIsInstance(source, StreamingSourceWithSize)self.assertEqual(source.size, len(read_test_image_file("img.png")))image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")diff --git a/zerver/tests/test_upload_s3.py b/zerver/tests/test_upload_s3.pyindex ce540e714e9..99033af96e9 100644--- a/zerver/tests/test_upload_s3.py+++ b/zerver/tests/test_upload_s3.py@@ -34,7 +34,7 @@ from zerver.lib.thumbnail import ()from zerver.lib.upload import (all_message_attachments,- attachment_vips_source,+ attachment_source,delete_export_tarball,delete_message_attachment,delete_message_attachments,@@ -82,7 +82,7 @@ class S3Test(ZulipTestCase):self.assertEqual(output.getvalue(), b"zulip!")@use_s3_backend- def test_attachment_vips_source(self) -> None:+ def test_attachment_source(self) -> None:create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)user_profile = self.example_user("hamlet")url = upload_message_attachment(@@ -90,7 +90,7 @@ class S3Test(ZulipTestCase):)[0]path_id = re.sub(r"/user_uploads/", "", url)- source = attachment_vips_source(path_id)+ source = attachment_source(path_id)self.assertIsInstance(source, StreamingSourceWithSize)self.assertEqual(source.size, len(read_test_image_file("img.png")))image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")diff --git a/zerver/views/tusd.py b/zerver/views/tusd.pyindex bef73c565c4..23b4db7f8ff 100644--- a/zerver/views/tusd.py+++ b/zerver/views/tusd.py@@ -19,7 +19,7 @@ from zerver.lib.rate_limiter import is_local_addrfrom zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpointfrom zerver.lib.upload import (RealmUploadQuotaError,- attachment_vips_source,+ attachment_source,check_upload_within_quota,create_attachment,delete_message_attachment,@@ -200,7 +200,7 @@ def handle_upload_pre_finish_hook(filename,path_id,content_type,- attachment_vips_source(path_id),+ attachment_source(path_id),user_profile,user_profile.realm,)diff --git a/zerver/views/upload.py b/zerver/views/upload.pyindex d15a79d15d5..321b6537525 100644--- a/zerver/views/upload.py+++ b/zerver/views/upload.py@@ -38,7 +38,7 @@ from zerver.lib.thumbnail import (get_image_thumbnail_path,)from zerver.lib.upload import (- attachment_vips_source,+ attachment_source,check_upload_within_quota,get_public_upload_root_url,maybe_add_charset,@@ -135,7 +135,7 @@ def serve_local(if content_type is None:content_type = guess_type(filename)[0] or "application/octet-stream"- content_type = maybe_add_charset(content_type, attachment_vips_source(path_id))+ content_type = maybe_add_charset(content_type, attachment_source(path_id))download = force_download or bare_content_type(content_type) not in INLINE_MIME_TYPESif settings.DEVELOPMENT: