Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

upload: Rename .source to .vips_source.

Alex Vandiver183da665ac39
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.py
index 0108a292651..a9afdc05ab1 100644
--- a/zerver/lib/upload/__init__.py
+++ b/zerver/lib/upload/__init__.py
@@ -58,10 +58,10 @@ def create_attachment(
)
if isinstance(file_data, bytes):
file_size = len(file_data)
- file_real_data: bytes | pyvips.Source = file_data
+ file_vips_data: bytes | pyvips.Source = file_data
else:
file_size = file_data.size
- file_real_data = file_data.source
+ file_vips_data = file_data.vips_source
attachment = Attachment.objects.create(
file_name=file_name,
path_id=path_id,
@@ -70,7 +70,7 @@ def create_attachment(
size=file_size,
content_type=content_type,
)
- maybe_thumbnail(file_real_data, content_type, path_id, realm.id)
+ maybe_thumbnail(file_vips_data, content_type, path_id, realm.id)
from zerver.actions.uploads import notify_attachment_update
notify_attachment_update(user_profile, "add", attachment.to_dict())
diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.py
index b7fcee488de..bef7800d198 100644
--- a/zerver/lib/upload/base.py
+++ b/zerver/lib/upload/base.py
@@ -12,7 +12,7 @@ from zerver.models import Realm, UserProfile
@dataclass
class StreamingSourceWithSize:
size: int
- source: pyvips.Source
+ vips_source: pyvips.Source
class ZulipUploadBackend:
diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.py
index 54a62269f19..2e65d6746eb 100644
--- a/zerver/lib/upload/local.py
+++ b/zerver/lib/upload/local.py
@@ -106,8 +106,11 @@ class LocalUploadBackend(ZulipUploadBackend):
def attachment_vips_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)
- source = pyvips.Source.new_from_file(file_path)
- return StreamingSourceWithSize(size=os.path.getsize(file_path), source=source)
+ vips_source = pyvips.Source.new_from_file(file_path)
+ return StreamingSourceWithSize(
+ size=os.path.getsize(file_path),
+ vips_source=vips_source,
+ )
@override
def delete_message_attachment(self, path_id: str) -> bool:
diff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.py
index d1e49af7e9d..ffbffecb2b7 100644
--- a/zerver/lib/upload/s3.py
+++ b/zerver/lib/upload/s3.py
@@ -279,9 +279,12 @@ class S3UploadBackend(ZulipUploadBackend):
def s3_read(streamingbody: StreamingBody, size: int) -> bytes:
return streamingbody.read(amt=size)
- source: pyvips.Source = pyvips.SourceCustom()
- source.on_read(partial(s3_read, metadata["Body"]))
- return StreamingSourceWithSize(size=metadata["ContentLength"], source=source)
+ vips_source: pyvips.Source = pyvips.SourceCustom()
+ vips_source.on_read(partial(s3_read, metadata["Body"]))
+ return StreamingSourceWithSize(
+ size=metadata["ContentLength"],
+ vips_source=vips_source,
+ )
@override
def delete_message_attachment(self, path_id: str) -> bool:
diff --git a/zerver/tests/test_upload_local.py b/zerver/tests/test_upload_local.py
index 4e86b164105..2311e07b308 100644
--- a/zerver/tests/test_upload_local.py
+++ b/zerver/tests/test_upload_local.py
@@ -64,7 +64,7 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
source = attachment_vips_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.source, "", access="sequential")
+ image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")
self.assertEqual(128, image.height)
self.assertEqual(128, image.width)
diff --git a/zerver/tests/test_upload_s3.py b/zerver/tests/test_upload_s3.py
index 848d226a398..ce540e714e9 100644
--- a/zerver/tests/test_upload_s3.py
+++ b/zerver/tests/test_upload_s3.py
@@ -93,7 +93,7 @@ class S3Test(ZulipTestCase):
source = attachment_vips_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.source, "", access="sequential")
+ image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")
self.assertEqual(128, image.height)
self.assertEqual(128, image.width)