Skip to content

Commit

Permalink
fixup! fixup! fixup! Update URL structure
Browse files Browse the repository at this point in the history
  • Loading branch information
martijngastkemper committed Jun 30, 2023
1 parent 1f68e50 commit 399c2f3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ The URL structure has changed to make it possible to add more options. The old U

Some examples:

- `/scaled/500x500/foobar.jpg` -> `/scaled/width:500|height:500/foobar.jpg`
- `/scaled/x400/foobar.jpg.webp` -> `/scaled/height:400|convert:webp/foobar.jpg.webp`
- `/scaled/500x500/foobar.jpg` -> `/scaled/width:500_height:500/foobar.jpg`
- `/scaled/x400/foobar.jpg.webp` -> `/scaled/height:400_convert:webp/foobar.jpg.webp`

# Upgrade to V3

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ Subsequent requests to the bucket will therefore skip the Lambda function entire

The function will allow resizing of images, by width, height, or both dimensions. Example paths:

- `/scaled/width:500|height:500/foobar.jpg`: this would generate a 500x500 version of the image `foobar.jpg`.
- `/scaled/width:500_height:500/foobar.jpg`: this would generate a 500x500 version of the image `foobar.jpg`.
- `/scaled/width:500/foobar.jpg`: omitting the `height` would generate a 500px wide version of the image.
- `/scaled/height:500/foobar.jpg`: omitting the `width` would generate a 500px high version of the image.

### File conversion

You can convert an image to a different format.

- `/scaled/width:500|height:500|convert:webp/foobar.jpg.webp`: this will create a **webp** version of the file `foobar.jpg`, scaled to 500x500.
- `/scaled/width:500_height:500_convert:webp/foobar.jpg.webp`: this will create a **webp** version of the file `foobar.jpg`, scaled to 500x500.

## Versions

Expand Down Expand Up @@ -102,7 +102,7 @@ This package includes a local image server, allowing you to test with this image
yarn serve
```

Then use http://localhost:8888/scaled/width:500|height:500/foo/bar.jpg for your image requests.
Then use http://localhost:8888/scaled/width:500_height:500/foo/bar.jpg for your image requests.

Currently, you will get back a random image with the requested dimensions.

Expand Down
2 changes: 1 addition & 1 deletion test/parseOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const parseOptions = require("../util/parseOptions.js");

it("should parse the options", function () {
expect(parseOptions("width:100")).toEqual({ width: "100" });
expect(parseOptions("width:100|height:200")).toEqual({
expect(parseOptions("width:100_height:200")).toEqual({
width: "100",
height: "200",
});
Expand Down
8 changes: 4 additions & 4 deletions test/pathToParams.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const pathToParams = require("../util/pathToParams.js");
describe("pathToParams", () => {
describe("Given a URL with both dimensions and no output-format", () => {
it("Will extract dimensions and use the original extension as outputFormat", () => {
const input = "scaled/width:500|height:320/foo.jpg";
const input = "scaled/width:500_height:320/foo.jpg";
const [options, path] = pathToParams(input);
expect(options.width).toBe("500");
expect(options.height).toBe("320");
Expand All @@ -32,7 +32,7 @@ describe("pathToParams", () => {
});
describe("Given a URL with a longer directory path", () => {
it("Will extract the correct path", () => {
const input = "/scaled/width:500|height:500/my/deeper/folder/foo.jpg";
const input = "/scaled/width:500_height:500/my/deeper/folder/foo.jpg";
const [options, path] = pathToParams(input, ["jpg"]);
expect(options.width).toBe("500");
expect(options.height).toBe("500");
Expand All @@ -41,7 +41,7 @@ describe("pathToParams", () => {
});
describe("Given a file with a double extension", () => {
it("Will treat the first extension as part of the original filename, and the last part as the outputFormat", () => {
const input = "/scaled/width:300|height:120|convert:png/foo.jpg.png";
const input = "/scaled/width:300_height:120_convert:png/foo.jpg.png";
const [options, path] = pathToParams(input);
const inputFormat = getInputFormat(path, options.convert);
const outputFormat = getOutputFormat(path, options.convert);
Expand All @@ -52,7 +52,7 @@ describe("pathToParams", () => {
expect(inputFormat).toBe("jpg");
});
it("Will be able to handle repeating extensions.", () => {
const input = "/scaled/width:300|height:120/foo.jpg.jpg";
const input = "/scaled/width:300_height:120/foo.jpg.jpg";
const [options, path] = pathToParams(input);
expect(options.width).toBe("300");
expect(options.height).toBe("120");
Expand Down
2 changes: 1 addition & 1 deletion util/parseOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
module.exports = (optionsString) => {
let options = {};

optionsString.split("|").forEach((option) => {
optionsString.split("_").forEach((option) => {
const [action, ...params] = option.split(":");
// Currently only one parameter is supported.
options[action] = params[0];
Expand Down

0 comments on commit 399c2f3

Please sign in to comment.