Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MERC-9364 Use CDN Original images for webdav - cache control #298

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion helpers/lib/cdnify.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ module.exports = globals => {
}

if (protocol === 'webdav:') {
return [cdnUrl, 'content', path].join('/');
const imgRegex = /.(jpg|jpeg|gif|png)$/i;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have somewhere documented the list of supported extensions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const isImage = imgRegex.test(path);
const prefix = isImage ? 'images/stencil/original/content' : 'content'
return [cdnUrl, prefix, path].join('/');
}

if (cdnSettings) {
Expand Down
33 changes: 27 additions & 6 deletions spec/helpers/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,40 @@ describe('cdn helper', function () {
], done);
});

it('should return a webDav asset if webdav protocol specified', function (done) {
it('should return an original cdn img asset if webdav protocol specified but file type indicates it is an image', function (done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering if we can create functional tests for such cases?

runTestCases([
{
input: '{{cdn "webdav:img/image.jpg"}}',
output: 'https://cdn.bcapp/3dsf74g/content/img/image.jpg',
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.jpg',
},
{
input: '{{cdn "webdav:/img/image.jpg"}}',
output: 'https://cdn.bcapp/3dsf74g/content/img/image.jpg',
input: '{{cdn "webdav:/img/image.jpeg"}}',
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.jpeg',
},
{
input: '{{cdn "webdav://img/image.jpg"}}',
output: 'https://cdn.bcapp/3dsf74g/content/img/image.jpg',
input: '{{cdn "webdav://img/image.gif"}}',
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.gif',
},
{
input: '{{cdn "webdav://img/image.png"}}',
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.png',
},
], done);
});

it('should return a webDav asset if webdav protocol specified but is not a supported image type', function (done) {
runTestCases([
{
input: '{{cdn "webdav:img/image.pdf"}}',
output: 'https://cdn.bcapp/3dsf74g/content/img/image.pdf',
},
{
input: '{{cdn "webdav:/img/image.pdf"}}',
output: 'https://cdn.bcapp/3dsf74g/content/img/image.pdf',
},
{
input: '{{cdn "webdav://img/image.pdf"}}',
output: 'https://cdn.bcapp/3dsf74g/content/img/image.pdf',
},
], done);
});
Expand Down