Skip to content

Commit

Permalink
Merge branch 'add-image-thumbnails-#29' into add-primary-images-#31
Browse files Browse the repository at this point in the history
  • Loading branch information
joelvdavies committed Oct 15, 2024
2 parents cf901f7 + 70ec4d1 commit 5a99c12
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ Listed below are the environment variables supported by the application.
| `OBJECT_STORAGE__BUCKET_NAME` | The name of the S3 bucket to use for object storage. | Yes | |
| `OBJECT_STORAGE__PRESIGNED_URL_EXPIRY_SECONDS` | The expiry time of presigned URLs. | Yes | |
| `ATTACHMENT__MAX_SIZE_BYTES` | The maximum file size of an attachment given in bytes. | Yes | |
| `IMAGE__THUMBNAIL_MAX_SIZE_BYTES` | The maximum width/height of generated image thumbnails. The actual width and height should maintain the original aspect ratio but neither the width nor height will exceed this value. |
| `IMAGE__THUMBNAIL_MAX_SIZE_BYTES` | The maximum width/height of generated image thumbnails. The actual width and height should maintain the original aspect ratio but neither the width nor height will exceed this value. | Yes | |
2 changes: 1 addition & 1 deletion object_storage_api/models/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ImageBase(BaseModel):
file_name: str
# Key of the image file in object storage
object_key: str
thumbnail: str
thumbnail_base64: str
primary: bool = False
title: Optional[str] = None
description: Optional[str] = None
Expand Down
2 changes: 1 addition & 1 deletion object_storage_api/routers/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
def create_image(
image_service: ImageServiceDep,
# Unfortunately using Annotated[ImagePostSchema, Form()] as on
# https://fastapi.tiangolo.com/tutorial/request-form-models/does not work correctly when there is an UploadFile
# https://fastapi.tiangolo.com/tutorial/request-form-models/ does not work correctly when there is an UploadFile
# within it, so have to redefine here before passing them to the schema
entity_id: Annotated[str, Form(description="ID of the entity the image relates to")],
upload_file: Annotated[UploadFile, File(description="Image file")],
Expand Down
2 changes: 1 addition & 1 deletion object_storage_api/schemas/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ class ImageSchema(CreatedModifiedSchemaMixin, ImagePostMetadataSchema):

id: str = Field(description="ID of the image")
file_name: str = Field(description="File name of the image")
thumbnail: str = Field(description="Thumbnail of the image as a byte string")
primary: bool = Field(description="Whether the image is the primary for its related entity")
thumbnail_base64: str = Field(description="Thumbnail of the image as a base64 encoded byte string")
4 changes: 2 additions & 2 deletions object_storage_api/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def create(self, image_metadata: ImagePostMetadataSchema, upload_file: UploadFil
image_id = str(ObjectId())

# Generate the thumbnail
thumbnail = generate_thumbnail_base64_str(upload_file)
thumbnail_base64 = generate_thumbnail_base64_str(upload_file)

# Upload the full size image to object storage
object_key = self._image_store.upload(image_id, image_metadata, upload_file)
Expand All @@ -64,7 +64,7 @@ def create(self, image_metadata: ImagePostMetadataSchema, upload_file: UploadFil
id=image_id,
file_name=upload_file.filename,
object_key=object_key,
thumbnail=thumbnail,
thumbnail_base64=thumbnail_base64,
)
except InvalidObjectIdError as exc:
# Provide more specific detail
Expand Down
6 changes: 3 additions & 3 deletions test/mock_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
**CREATED_MODIFIED_GET_DATA_EXPECTED,
"id": ANY,
"file_name": "image.jpg",
"thumbnail": "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA",
"primary": False,
"thumbnail_base64": "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA",
"title": None,
"description": None,
}
Expand All @@ -103,7 +103,7 @@
"id": str(ObjectId()),
"file_name": "image.jpg",
"object_key": "images/65df5ee771892ddcc08bd28f/65e0a624d64aaae884abaaee",
"thumbnail": "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA",
"thumbnail_base64": "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA",
}

IMAGE_GET_DATA_ALL_VALUES = {
Expand All @@ -112,5 +112,5 @@
"id": ANY,
"file_name": "image.jpg",
"primary": False,
"thumbnail": "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA",
"thumbnail_base64": "UklGRjQAAABXRUJQVlA4ICgAAADQAQCdASoCAAEAAUAmJYwCdAEO/gOOAAD+qlQWHDxhNJOjVlqIb8AA",
}
6 changes: 3 additions & 3 deletions test/unit/services/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def mock_create(self, image_post_metadata_data: dict) -> None:
self.mock_object_id.return_value = self._expected_image_id

# Thumbnail
expected_thumbnail = "some_thumbnail"
self.mock_generate_thumbnail_base64_str.return_value = expected_thumbnail
expected_thumbnail_base64 = "some_thumbnail"
self.mock_generate_thumbnail_base64_str.return_value = expected_thumbnail_base64

# Store
expected_object_key = "some/object/key"
Expand All @@ -90,7 +90,7 @@ def mock_create(self, image_post_metadata_data: dict) -> None:
id=str(self._expected_image_id),
object_key=expected_object_key,
file_name=self._upload_file.filename,
thumbnail=expected_thumbnail,
thumbnail_base64=expected_thumbnail_base64,
)

# Repo (The contents of the returned output model does not matter here as long as its valid)
Expand Down

0 comments on commit 5a99c12

Please sign in to comment.