Skip to content

Commit

Permalink
fix: MERC-9364 Use CDN Original images for webdav - cache control
Browse files Browse the repository at this point in the history
  • Loading branch information
christensenep committed Dec 29, 2023
1 parent 2cacbed commit 06cc938
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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;
const isImage = imgRegex.test(path);
const prefix = isImage ? 'images/stencil/original/content' : 'content'
return [cdnUrl, prefix, path].join('/');
}

if (cdnSettings) {
Expand Down
25 changes: 21 additions & 4 deletions spec/helpers/cdn.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,36 @@ 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) {
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',
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',
output: 'https://cdn.bcapp/3dsf74g/images/stencil/original/content/img/image.jpg',
},
], 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

0 comments on commit 06cc938

Please sign in to comment.