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 a52423f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 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
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) {
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

0 comments on commit a52423f

Please sign in to comment.