From 8a330f5bd7e8f5b8355761b96e5353bc93eca11d Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Thu, 28 Dec 2023 16:46:21 -0800 Subject: [PATCH] fix: MERC-9364 Use CDN Original images for webdav - cache control --- helpers/lib/cdnify.js | 5 ++++- spec/helpers/cdn.js | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/helpers/lib/cdnify.js b/helpers/lib/cdnify.js index f23c346..61c9cad 100644 --- a/helpers/lib/cdnify.js +++ b/helpers/lib/cdnify.js @@ -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) { diff --git a/spec/helpers/cdn.js b/spec/helpers/cdn.js index b469bc2..ff60421 100644 --- a/spec/helpers/cdn.js +++ b/spec/helpers/cdn.js @@ -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); });