Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Write test for image path schema #13

Open
scytherswings opened this issue May 3, 2018 · 4 comments
Open

Write test for image path schema #13

scytherswings opened this issue May 3, 2018 · 4 comments

Comments

@scytherswings
Copy link
Contributor

The regex
const IMAGE_KEY_PATTERN_REGEX = /(([\/a-zA-Z0-9]+)\/([a-zA-Z0-9]+))_((\d+|auto)x(\d+|auto))(\.jpeg|\.jpg|\.png)/;

Is large and needs to be tested to make sure future changes don't break our filename schema.
The way images are currently resolved is by taking the s3 path of the failed image request, usually something like raw/1283ds7320dofiuasdofisddgn_400x300 and extracting the original file from it.
In this case it would be 1283ds7320dofiuasdofisddgn and we know that the user wants an image that is 400 pixels wide by 300 tall, respecting the aspect ratio (this is not the scope of this test though).

We need a test that will ensure that requests coming in for new image sizes are parsed and the original image path is extracted correctly.

@scytherswings
Copy link
Contributor Author

We should also make sure that auto image sizes work, but autoxauto is not valid

@stretch1414
Copy link
Contributor

How exactly does auto work?

@scytherswings
Copy link
Contributor Author

Also rejecting malformed sizes would be good, though more or less optional I'd say. A nice error message if you request 400x12032084438943257452435 would be hepful

@scytherswings
Copy link
Contributor Author

scytherswings commented May 3, 2018

Basically Sharp will guarantee that the other dimension is met exactly. Basically auto allows users to know all images will be X pixels tall, etc.
Ex: 400xauto will always come out 400 pixels wide, whereas 400x500 will be maximized to this dimension while still respecting the aspect ratio of the image, so it could come out 395x500 or something. The .max() argument is what provides this behavior from Sharp, just FYI.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants