Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from fishbrain/support-alternative-thumbor-filt…
Browse files Browse the repository at this point in the history
…er-syntax

Support alternative Thumbor filter syntax
  • Loading branch information
evdokimovn authored Aug 13, 2021
2 parents e7226f5 + 7ec0263 commit 84cfcea
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 44 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Tests
on: [push]
jobs:
unit-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Unit test
run: |
cd deployment
chmod +x ./run-unit-tests.sh
./run-unit-tests.sh
2 changes: 1 addition & 1 deletion source/image-handler/image-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ImageRequest {
path = path.replace(matchPattern, substitution);
}
}
return decodeURIComponent(path.replace(/\/meta|\/(\d+x\d+)\/|filters:[^\)]+|smart\/|\/fit-in+|^\/+/g, '').replace(/\)/g, '').replace(/^\/+/, ''));
return decodeURIComponent(path.replace(/\/meta|\/(\d+x\d+)\/|filters(:[^\)]+\))+|smart\/|\/fit-in+|^\/+/g, '').replace(/\)/g, '').replace(/^\/+/, ''));
}

// Return an error for all other conditions
Expand Down
2 changes: 1 addition & 1 deletion source/image-handler/test/image-request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ describe('parseImageKey()', function() {
it('Should pass if an image key value is provided in the thumbor request format', function() {
// Arrange
const event = {
path : '/meta/fit-in/100x100/filters:rotate(90)/filters:no_upscale()/thumbor-image.jpg'
path : '/meta/fit-in/100x100/smart/filters:rotate(90)/filters:no_upscale()/filters:blur(90):format(png)/thumbor-image.jpg'
}
// Act
const imageRequest = new ImageRequest(s3, secretsManager);
Expand Down
98 changes: 61 additions & 37 deletions source/image-handler/test/thumbor-mapping.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,30 @@ describe('process()', function() {
expect(thumborMapping.edits).toEqual(expectedResult.edits);
});
});
describe('001/thumborRequest', function() {
it('Should pass if the proper edit translations are applied and in the correct order', function() {
// Arrange
const event = {
path : "/fit-in/200x300/filters:grayscale():format(png)/test-image-001.jpg"
}
// Act
const thumborMapping = new ThumborMapping();
thumborMapping.process(event);
// Assert
const expectedResult = {
edits: {
resize: {
width: 200,
height: 300,
fit: 'inside'
},
grayscale: true,
toFormat: 'png'
}
};
expect(thumborMapping.edits).toEqual(expectedResult.edits);
});
});
describe('002/resize/fit-in', function() {
it('Should pass if the proper edit translations are applied and in the correct order', function() {
// Arrange
Expand Down Expand Up @@ -220,7 +244,7 @@ describe('parseCustomPath()', function() {
it('Should throw an error if the path is not defined', function() {
const event = {};
process.env.REWRITE_MATCH_PATTERN = /(filters-)/gm;
process.env.REWRITE_SUBSTITUTION = 'filters:';
process.env.REWRITE_SUBSTITUTION = '';
// Act
const thumborMapping = new ThumborMapping();
// Assert
Expand Down Expand Up @@ -251,7 +275,7 @@ describe('mapFilter()', function() {
describe('001/autojpg', function() {
it('Should pass if the filter is successfully converted from Thumbor:autojpg()', function() {
// Arrange
const edit = 'filters:autojpg()';
const edit = 'autojpg()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -266,7 +290,7 @@ describe('mapFilter()', function() {
describe('002/background_color', function() {
it('Should pass if the filter is successfully translated from Thumbor:background_color()', function() {
// Arrange
const edit = 'filters:background_color(ffff)';
const edit = 'background_color(ffff)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -281,7 +305,7 @@ describe('mapFilter()', function() {
describe('003/blur/singleParameter', function() {
it('Should pass if the filter is successfully translated from Thumbor:blur()', function() {
// Arrange
const edit = 'filters:blur(60)';
const edit = 'blur(60)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -297,7 +321,7 @@ describe('mapFilter()', function() {
describe('004/blur/doubleParameter', function() {
it('Should pass if the filter is successfully translated from Thumbor:blur()', function() {
// Arrange
const edit = 'filters:blur(60, 2)';
const edit = 'blur(60, 2)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -312,7 +336,7 @@ describe('mapFilter()', function() {
describe('005/convolution', function() {
it('Should pass if the filter is successfully translated from Thumbor:convolution()', function() {
// Arrange
const edit = 'filters:convolution(1;2;1;2;4;2;1;2;1,3,true)';
const edit = 'convolution(1;2;1;2;4;2;1;2;1,3,true)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -331,7 +355,7 @@ describe('mapFilter()', function() {
describe('006/equalize', function() {
it('Should pass if the filter is successfully translated from Thumbor:equalize()', function() {
// Arrange
const edit = 'filters:equalize()';
const edit = 'equalize()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -346,7 +370,7 @@ describe('mapFilter()', function() {
describe('007/fill/resizeUndefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:fill()', function() {
// Arrange
const edit = 'filters:fill(fff)';
const edit = 'fill(fff)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -362,7 +386,7 @@ describe('mapFilter()', function() {
describe('008/fill/resizeDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:fill()', function() {
// Arrange
const edit = 'filters:fill(fff)';
const edit = 'fill(fff)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -378,7 +402,7 @@ describe('mapFilter()', function() {
describe('009/format/supportedFileType', function() {
it('Should pass if the filter is successfully translated from Thumbor:format()', function() {
// Arrange
const edit = 'filters:format(png)';
const edit = 'format(png)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -393,7 +417,7 @@ describe('mapFilter()', function() {
describe('010/format/unsupportedFileType', function() {
it('Should return undefined if an accepted file format is not specified', function() {
// Arrange
const edit = 'filters:format(test)';
const edit = 'format(test)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -408,7 +432,7 @@ describe('mapFilter()', function() {
describe('011/no_upscale/resizeUndefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:no_upscale()', function() {
// Arrange
const edit = 'filters:no_upscale()';
const edit = 'no_upscale()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -427,7 +451,7 @@ describe('mapFilter()', function() {
describe('012/no_upscale/resizeDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:no_upscale()', function() {
// Arrange
const edit = 'filters:no_upscale()';
const edit = 'no_upscale()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -452,7 +476,7 @@ describe('mapFilter()', function() {
describe('013/proportion/resizeDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:proportion()', function() {
// Arrange
const edit = 'filters:proportion(0.3)';
const edit = 'proportion(0.3)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -478,7 +502,7 @@ describe('mapFilter()', function() {
describe('014/proportion/resizeUndefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:resize()', function() {
// Arrange
const edit = 'filters:proportion(0.3)';
const edit = 'proportion(0.3)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -492,7 +516,7 @@ describe('mapFilter()', function() {
describe('015/quality/jpg', function() {
it('Should pass if the filter is successfully translated from Thumbor:quality()', function() {
// Arrange
const edit = 'filters:quality(50)';
const edit = 'quality(50)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -511,7 +535,7 @@ describe('mapFilter()', function() {
describe('016/quality/png', function() {
it('Should pass if the filter is successfully translated from Thumbor:quality()', function() {
// Arrange
const edit = 'filters:quality(50)';
const edit = 'quality(50)';
const filetype = 'png';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -530,7 +554,7 @@ describe('mapFilter()', function() {
describe('017/quality/webp', function() {
it('Should pass if the filter is successfully translated from Thumbor:quality()', function() {
// Arrange
const edit = 'filters:quality(50)';
const edit = 'quality(50)';
const filetype = 'webp';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -549,7 +573,7 @@ describe('mapFilter()', function() {
describe('018/quality/tiff', function() {
it('Should pass if the filter is successfully translated from Thumbor:quality()', function() {
// Arrange
const edit = 'filters:quality(50)';
const edit = 'quality(50)';
const filetype = 'tiff';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -568,7 +592,7 @@ describe('mapFilter()', function() {
describe('019/quality/heif', function() {
it('Should pass if the filter is successfully translated from Thumbor:quality()', function() {
// Arrange
const edit = 'filters:quality(50)';
const edit = 'quality(50)';
const filetype = 'heif';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -587,7 +611,7 @@ describe('mapFilter()', function() {
describe('020/quality/other', function() {
it('Should return undefined if an unsupported file type is provided', function() {
// Arrange
const edit = 'filters:quality(50)';
const edit = 'quality(50)';
const filetype = 'xml';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -602,7 +626,7 @@ describe('mapFilter()', function() {
describe('021/rgb', function() {
it('Should pass if the filter is successfully translated from Thumbor:rgb()', function() {
// Arrange
const edit = 'filters:rgb(10, 10, 10)';
const edit = 'rgb(10, 10, 10)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -623,7 +647,7 @@ describe('mapFilter()', function() {
describe('022/rotate', function() {
it('Should pass if the filter is successfully translated from Thumbor:rotate()', function() {
// Arrange
const edit = 'filters:rotate(75)';
const edit = 'rotate(75)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -640,7 +664,7 @@ describe('mapFilter()', function() {
describe('023/sharpen', function() {
it('Should pass if the filter is successfully translated from Thumbor:sharpen()', function() {
// Arrange
const edit = 'filters:sharpen(75, 5)';
const edit = 'sharpen(75, 5)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -657,7 +681,7 @@ describe('mapFilter()', function() {
describe('024/stretch/default', function() {
it('Should pass if the filter is successfully translated from Thumbor:stretch()', function() {
// Arrange
const edit = 'filters:stretch()';
const edit = 'stretch()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -674,7 +698,7 @@ describe('mapFilter()', function() {
describe('025/stretch/resizeDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:stretch()', function() {
// Arrange
const edit = 'filters:stretch()';
const edit = 'stretch()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -699,7 +723,7 @@ describe('mapFilter()', function() {
describe('026/stretch/fit-in', function() {
it('Should pass if the filter is successfully translated from Thumbor:stretch()', function() {
// Arrange
const edit = 'filters:stretch()';
const edit = 'stretch()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -719,7 +743,7 @@ describe('mapFilter()', function() {
describe('027/stretch/fit-in/resizeDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:stretch()', function() {
// Arrange
const edit = 'filters:stretch()';
const edit = 'stretch()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -745,7 +769,7 @@ describe('mapFilter()', function() {
describe('028/strip_exif', function() {
it('Should pass if the filter is successfully translated from Thumbor:strip_exif()', function() {
// Arrange
const edit = 'filters:strip_exif()';
const edit = 'strip_exif()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -762,7 +786,7 @@ describe('mapFilter()', function() {
describe('029/strip_icc', function() {
it('Should pass if the filter is successfully translated from Thumbor:strip_icc()', function() {
// Arrange
const edit = 'filters:strip_icc()';
const edit = 'strip_icc()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -779,7 +803,7 @@ describe('mapFilter()', function() {
describe('030/upscale', function() {
it('Should pass if the filter is successfully translated from Thumbor:upscale()', function() {
// Arrange
const edit = 'filters:upscale()';
const edit = 'upscale()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -798,7 +822,7 @@ describe('mapFilter()', function() {
describe('031/upscale/resizeNotUndefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:upscale()', function() {
// Arrange
const edit = 'filters:upscale()';
const edit = 'upscale()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -818,7 +842,7 @@ describe('mapFilter()', function() {
describe('032/watermark/positionDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:watermark()', function() {
// Arrange
const edit = 'filters:watermark(bucket,key,100,100,0)';
const edit = 'watermark(bucket,key,100,100,0)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -845,7 +869,7 @@ describe('mapFilter()', function() {
describe('033/watermark/positionDefinedByPercentile', function() {
it('Should pass if the filter is successfully translated from Thumbor:watermark()', function() {
// Arrange
const edit = 'filters:watermark(bucket,key,50p,30p,0)';
const edit = 'watermark(bucket,key,50p,30p,0)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -872,7 +896,7 @@ describe('mapFilter()', function() {
describe('034/watermark/positionDefinedWrong', function() {
it('Should pass if the filter is successfully translated from Thumbor:watermark()', function() {
// Arrange
const edit = 'filters:watermark(bucket,key,x,x,0)';
const edit = 'watermark(bucket,key,x,x,0)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -896,7 +920,7 @@ describe('mapFilter()', function() {
describe('035/watermark/ratioDefined', function() {
it('Should pass if the filter is successfully translated from Thumbor:watermark()', function() {
// Arrange
const edit = 'filters:watermark(bucket,key,100,100,0,10,10)';
const edit = 'watermark(bucket,key,100,100,0,10,10)';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand All @@ -923,7 +947,7 @@ describe('mapFilter()', function() {
describe('036/elseCondition', function() {
it('Should pass if undefined is returned for an unsupported filter', function() {
// Arrange
const edit = 'filters:notSupportedFilter()';
const edit = 'notSupportedFilter()';
const filetype = 'jpg';
// Act
const thumborMapping = new ThumborMapping();
Expand Down
Loading

0 comments on commit 84cfcea

Please sign in to comment.