Skip to content

Recognize .webp as a valid scaled-derivative extension #66

Description

@jdub233

The lambda's request-routing logic in getOrCreateObject.js filters scaled-derivative requests by extension whitelist:

const sizeMatch = pathname.match(/-(\d+)x(\d+)\.(jpg|jpeg|png|gif)$/);

.webp is not included. Requests for image-300x200.webp don't match sizeMatch, fall through the "is this a render request" branch, and 404. The Sharp invocation itself is format-agnostic (no explicit .toFormat() is set, so output format follows input), so once routing matches .webp, end-to-end rendering works without further changes.

This would be an enabling change for the efforts around the Questrom site migration. That site's WordPress database already carries correct .webp size-suffix references, so this regex fix unblocks rendering for those assets.

Goals

  • Add webp to the sizeMatch regex in getOrCreateObject.js
  • Add webp to the originalPath reconstruction regex in the same file's NoSuchKey branch
  • Delete the unused getOriginalS3Key() function in resizeAndSave.js (carries a stale narrower regex (jpg|png); the path math is now done in getOrCreateObject.js)
  • Add a WebP fixture to the test suite (sequence this first for test-driven development)

Acceptance criteria

  • A request for a WebP scaled derivative whose original exists at original_media/... generates and serves the resized .webp correctly
  • Existing jpg/jpeg/png/gif behavior unchanged
  • WebP references in the Questrom WP database resolve end-to-end against a dev deployment

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions