Bring the application, own tests, Dockerfile, toolchain, compose stack,
HAProxy, k6, RustFS and RabbitMQ configuration, migrations, hooks,
scenario scripts and the CI job from the lab 5 solution commit 64d5c67,
keep the lab 5 Makefile targets on top of the unchanged skeleton
targets, and append the lab 5 solution variables to the skeleton
.env.example. The package and the application follow the contract
version 1.6.0, and the image, the throwaway test containers and the
broker vhost description are tagged lab6 so they do not collide with a
lab 5 stand on the same host.
This is the starting point of the lab 6 cycle: lint, own tests and the
offline skeleton check pass before any lab 6 change.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
36 lines
845 B
Python
36 lines
845 B
Python
from dataclasses import dataclass
|
|
from uuid import UUID
|
|
|
|
THUMBNAIL = "thumbnail"
|
|
CROP = "crop"
|
|
OPTIMIZED = "optimized"
|
|
THUMBNAIL_BOX = 256
|
|
CROP_SIDE = 128
|
|
OPTIMIZED_BOX = 1280
|
|
VARIANTS_PREFIX = "variants/"
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Variant:
|
|
name: str
|
|
content_type: str
|
|
size_bytes: int
|
|
width: int
|
|
height: int
|
|
sha256: str
|
|
object_key: str
|
|
|
|
|
|
def fit(width: int, height: int, box: int) -> tuple[int, int]:
|
|
if max(width, height) <= box:
|
|
return width, height
|
|
if width >= height:
|
|
return box, max(1, height * box // width)
|
|
return max(1, width * box // height), box
|
|
|
|
|
|
def variant_key(
|
|
attachment_id: UUID, pipeline_version: int, name: str, sha256: str, extension: str
|
|
) -> str:
|
|
return f"{VARIANTS_PREFIX}{attachment_id}/{pipeline_version}/{name}-{sha256[:16]}.{extension}"
|