Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/api/serializers/image_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def to_internal_value(self, data):
uuid = UUID(identifier)
except ValueError:
raise serializers.ValidationError(
{"Could not parse identifier from URL.": data["url"]}
{"url": ["Could not parse identifier from URL."]}
)

data["identifier"] = uuid
Expand Down
38 changes: 24 additions & 14 deletions api/api/views/image_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from drf_spectacular.utils import extend_schema, extend_schema_view
from PIL import Image as PILImage
import structlog

from api.constants.media_types import IMAGE_TYPE
from api.docs.image_docs import (
Expand All @@ -31,6 +32,9 @@
from api.views.media_views import MediaViewSet


logger = structlog.get_logger(__name__)


@extend_schema(tags=["images"])
@extend_schema_view(
list=search,
Expand Down Expand Up @@ -81,20 +85,26 @@ async def oembed(self, request, *_, **__):
image = await aget_object_or_404(Image, identifier=identifier)

if not (image.height and image.width):
session = await get_aiohttp_session()

async with session.get(
image.url, headers=self.OEMBED_HEADERS
) as image_file:
image_content = await image_file.content.read()

with PILImage.open(io.BytesIO(image_content)) as image_file:
width, height = image_file.size

context |= {
"width": width,
"height": height,
}
try:
session = await get_aiohttp_session()

async with session.get(
image.url, headers=self.OEMBED_HEADERS
) as image_file:
if image_file.status == 200:
image_content = await image_file.content.read()
with PILImage.open(io.BytesIO(image_content)) as image_file_obj:
width, height = image_file_obj.size
context |= {
"width": width,
"height": height,
}
except Exception:
logger.warning(
"failed_to_get_image_dimensions_for_oembed",
image_identifier=image.identifier,
image_url=image.url,
)

serializer = self.get_serializer(image, context=context)
return Response(data=await serializer.adata)
Expand Down
3 changes: 3 additions & 0 deletions dag-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ fi

# Pull out the subject from the new commit
subject=$(git log -1 --format='%s')
# Escape backslashes and double quotes for JSON payload safety
subject=${subject//\\/\\\\}
subject=${subject//\"/\\\"}
# Swap the < & > characters for their HTML entities so they aren't
# interpreted as delimiters by Slack
subject=${subject//>/&gt;}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/VSkipToContentButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import VButton from "~/components/VButton.vue"
</template>

<style scoped>
.skip-button:not(:focus-visible) {
.skip-button:not(:focus, :focus-visible) {
@apply sr-only;
}
</style>
Loading