mirror of
https://github.com/zulip/zulip.git
synced 2025-11-11 17:36:27 +00:00
upload: Rename attachment_vips_source, as it's not just for vips_source.
This commit is contained in:
committed by
Tim Abbott
parent
e37ee13577
commit
085d137871
@@ -249,8 +249,8 @@ def upload_message_attachment_from_request(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def attachment_vips_source(path_id: str) -> StreamingSourceWithSize:
|
def attachment_source(path_id: str) -> StreamingSourceWithSize:
|
||||||
return upload_backend.attachment_vips_source(path_id)
|
return upload_backend.attachment_source(path_id)
|
||||||
|
|
||||||
|
|
||||||
def save_attachment_contents(path_id: str, filehandle: IO[bytes]) -> None:
|
def save_attachment_contents(path_id: str, filehandle: IO[bytes]) -> None:
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class ZulipUploadBackend:
|
|||||||
def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:
|
def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:
|
def attachment_source(self, path_id: str) -> StreamingSourceWithSize:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def delete_message_attachment(self, path_id: str) -> bool:
|
def delete_message_attachment(self, path_id: str) -> bool:
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class LocalUploadBackend(ZulipUploadBackend):
|
|||||||
filehandle.write(chunk)
|
filehandle.write(chunk)
|
||||||
|
|
||||||
@override
|
@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)
|
file_path = os.path.join(assert_is_not_none(settings.LOCAL_UPLOADS_DIR), "files", path_id)
|
||||||
assert_is_local_storage_path("files", file_path)
|
assert_is_local_storage_path("files", file_path)
|
||||||
vips_source = pyvips.Source.new_from_file(file_path)
|
vips_source = pyvips.Source.new_from_file(file_path)
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ class S3UploadBackend(ZulipUploadBackend):
|
|||||||
filehandle.write(chunk)
|
filehandle.write(chunk)
|
||||||
|
|
||||||
@override
|
@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()
|
metadata = self.uploads_bucket.Object(path_id).get()
|
||||||
|
|
||||||
def s3_read(streamingbody: StreamingBody, size: int) -> bytes:
|
def s3_read(streamingbody: StreamingBody, size: int) -> bytes:
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from zerver.lib.thumbnail import (
|
|||||||
)
|
)
|
||||||
from zerver.lib.upload import (
|
from zerver.lib.upload import (
|
||||||
all_message_attachments,
|
all_message_attachments,
|
||||||
attachment_vips_source,
|
attachment_source,
|
||||||
create_attachment,
|
create_attachment,
|
||||||
save_attachment_contents,
|
save_attachment_contents,
|
||||||
upload_backend,
|
upload_backend,
|
||||||
@@ -746,7 +746,7 @@ class TestStoreThumbnail(ZulipTestCase):
|
|||||||
upload_backend.upload_message_attachment(
|
upload_backend.upload_message_attachment(
|
||||||
path_id, "img.png", "image/png", read_test_image_file("img.png"), hamlet
|
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)
|
create_attachment("img.png", path_id, "image/png", source, hamlet, hamlet.realm)
|
||||||
self.assertTrue(ImageAttachment.objects.filter(path_id=path_id).exists())
|
self.assertTrue(ImageAttachment.objects.filter(path_id=path_id).exists())
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from zerver.lib.test_helpers import get_test_image_file, read_test_image_file
|
|||||||
from zerver.lib.thumbnail import DEFAULT_EMOJI_SIZE, MEDIUM_AVATAR_SIZE, resize_avatar
|
from zerver.lib.thumbnail import DEFAULT_EMOJI_SIZE, MEDIUM_AVATAR_SIZE, resize_avatar
|
||||||
from zerver.lib.upload import (
|
from zerver.lib.upload import (
|
||||||
all_message_attachments,
|
all_message_attachments,
|
||||||
attachment_vips_source,
|
attachment_source,
|
||||||
delete_export_tarball,
|
delete_export_tarball,
|
||||||
delete_message_attachment,
|
delete_message_attachment,
|
||||||
delete_message_attachments,
|
delete_message_attachments,
|
||||||
@@ -54,14 +54,14 @@ class LocalStorageTest(UploadSerializeMixin, ZulipTestCase):
|
|||||||
save_attachment_contents(path_id, output)
|
save_attachment_contents(path_id, output)
|
||||||
self.assertEqual(output.getvalue(), b"zulip!")
|
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")
|
user_profile = self.example_user("hamlet")
|
||||||
url = upload_message_attachment(
|
url = upload_message_attachment(
|
||||||
"img.png", "image/png", read_test_image_file("img.png"), user_profile
|
"img.png", "image/png", read_test_image_file("img.png"), user_profile
|
||||||
)[0]
|
)[0]
|
||||||
path_id = re.sub(r"/user_uploads/", "", url)
|
path_id = re.sub(r"/user_uploads/", "", url)
|
||||||
|
|
||||||
source = attachment_vips_source(path_id)
|
source = attachment_source(path_id)
|
||||||
self.assertIsInstance(source, StreamingSourceWithSize)
|
self.assertIsInstance(source, StreamingSourceWithSize)
|
||||||
self.assertEqual(source.size, len(read_test_image_file("img.png")))
|
self.assertEqual(source.size, len(read_test_image_file("img.png")))
|
||||||
image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")
|
image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ from zerver.lib.thumbnail import (
|
|||||||
)
|
)
|
||||||
from zerver.lib.upload import (
|
from zerver.lib.upload import (
|
||||||
all_message_attachments,
|
all_message_attachments,
|
||||||
attachment_vips_source,
|
attachment_source,
|
||||||
delete_export_tarball,
|
delete_export_tarball,
|
||||||
delete_message_attachment,
|
delete_message_attachment,
|
||||||
delete_message_attachments,
|
delete_message_attachments,
|
||||||
@@ -82,7 +82,7 @@ class S3Test(ZulipTestCase):
|
|||||||
self.assertEqual(output.getvalue(), b"zulip!")
|
self.assertEqual(output.getvalue(), b"zulip!")
|
||||||
|
|
||||||
@use_s3_backend
|
@use_s3_backend
|
||||||
def test_attachment_vips_source(self) -> None:
|
def test_attachment_source(self) -> None:
|
||||||
create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)
|
create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)
|
||||||
user_profile = self.example_user("hamlet")
|
user_profile = self.example_user("hamlet")
|
||||||
url = upload_message_attachment(
|
url = upload_message_attachment(
|
||||||
@@ -90,7 +90,7 @@ class S3Test(ZulipTestCase):
|
|||||||
)[0]
|
)[0]
|
||||||
path_id = re.sub(r"/user_uploads/", "", url)
|
path_id = re.sub(r"/user_uploads/", "", url)
|
||||||
|
|
||||||
source = attachment_vips_source(path_id)
|
source = attachment_source(path_id)
|
||||||
self.assertIsInstance(source, StreamingSourceWithSize)
|
self.assertIsInstance(source, StreamingSourceWithSize)
|
||||||
self.assertEqual(source.size, len(read_test_image_file("img.png")))
|
self.assertEqual(source.size, len(read_test_image_file("img.png")))
|
||||||
image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")
|
image = pyvips.Image.new_from_source(source.vips_source, "", access="sequential")
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from zerver.lib.rate_limiter import is_local_addr
|
|||||||
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
|
||||||
from zerver.lib.upload import (
|
from zerver.lib.upload import (
|
||||||
RealmUploadQuotaError,
|
RealmUploadQuotaError,
|
||||||
attachment_vips_source,
|
attachment_source,
|
||||||
check_upload_within_quota,
|
check_upload_within_quota,
|
||||||
create_attachment,
|
create_attachment,
|
||||||
delete_message_attachment,
|
delete_message_attachment,
|
||||||
@@ -200,7 +200,7 @@ def handle_upload_pre_finish_hook(
|
|||||||
filename,
|
filename,
|
||||||
path_id,
|
path_id,
|
||||||
content_type,
|
content_type,
|
||||||
attachment_vips_source(path_id),
|
attachment_source(path_id),
|
||||||
user_profile,
|
user_profile,
|
||||||
user_profile.realm,
|
user_profile.realm,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ from zerver.lib.thumbnail import (
|
|||||||
get_image_thumbnail_path,
|
get_image_thumbnail_path,
|
||||||
)
|
)
|
||||||
from zerver.lib.upload import (
|
from zerver.lib.upload import (
|
||||||
attachment_vips_source,
|
attachment_source,
|
||||||
check_upload_within_quota,
|
check_upload_within_quota,
|
||||||
get_public_upload_root_url,
|
get_public_upload_root_url,
|
||||||
maybe_add_charset,
|
maybe_add_charset,
|
||||||
@@ -135,7 +135,7 @@ def serve_local(
|
|||||||
if content_type is None:
|
if content_type is None:
|
||||||
content_type = guess_type(filename)[0] or "application/octet-stream"
|
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_TYPES
|
download = force_download or bare_content_type(content_type) not in INLINE_MIME_TYPES
|
||||||
|
|
||||||
if settings.DEVELOPMENT:
|
if settings.DEVELOPMENT:
|
||||||
|
|||||||
Reference in New Issue
Block a user