thumbnail: Move get_image_thumbnail_path and split_thumbnail_path.

This commit is contained in:
Alex Vandiver
2024-07-17 01:11:57 +00:00
committed by Tim Abbott
parent d474600056
commit 4351cc5914
7 changed files with 26 additions and 40 deletions

View File

@@ -22,21 +22,12 @@ from zerver.lib.thumbnail import (
MEDIUM_AVATAR_SIZE,
THUMBNAIL_ACCEPT_IMAGE_TYPES,
BadImageError,
BaseThumbnailFormat,
maybe_thumbnail,
resize_avatar,
resize_emoji,
)
from zerver.lib.upload.base import INLINE_MIME_TYPES, ZulipUploadBackend
from zerver.models import (
Attachment,
ImageAttachment,
Message,
Realm,
RealmEmoji,
ScheduledMessage,
UserProfile,
)
from zerver.models import Attachment, Message, Realm, RealmEmoji, ScheduledMessage, UserProfile
from zerver.models.users import is_cross_realm_bot_email
@@ -136,22 +127,6 @@ def sanitize_name(value: str) -> str:
return value
def get_image_thumbnail_path(
image_attachment: ImageAttachment,
thumbnail_format: BaseThumbnailFormat,
) -> str:
return f"thumbnail/{image_attachment.path_id}/{thumbnail_format!s}"
def split_thumbnail_path(file_path: str) -> tuple[str, BaseThumbnailFormat]:
assert file_path.startswith("thumbnail/")
path_parts = file_path.split("/")
thumbnail_format = BaseThumbnailFormat.from_string(path_parts.pop())
assert thumbnail_format is not None
path_id = "/".join(path_parts[1:])
return path_id, thumbnail_format
def upload_message_attachment(
uploaded_file_name: str,
content_type: str,