From 46c6920b9c1c9337c77fa4c36f5e637046303df8 Mon Sep 17 00:00:00 2001 From: Erik Christensen Date: Thu, 28 Dec 2023 16:46:21 -0800 Subject: [PATCH 1/2] fix: MERC-9364 Use CDN Original images for webdav - cache control --- helpers/lib/cdnify.js | 5 ++++- spec/helpers/cdn.js | 33 +++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/helpers/lib/cdnify.js b/helpers/lib/cdnify.js index f23c346..1c8dd66 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..fcf2cfe 100644 --- a/spec/helpers/cdn.js +++ b/spec/helpers/cdn.js @@ -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); }); From 0c4651e6e0cb5be285058452fc77a17442056d68 Mon Sep 17 00:00:00 2001 From: Alexander Saiannyi Date: Tue, 25 Feb 2025 12:13:35 +0100 Subject: [PATCH 2/2] fix: SD-9364 remove regex for better performance --- helpers/lib/cdnify.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helpers/lib/cdnify.js b/helpers/lib/cdnify.js index 1c8dd66..59cb6ce 100644 --- a/helpers/lib/cdnify.js +++ b/helpers/lib/cdnify.js @@ -56,8 +56,8 @@ module.exports = globals => { } if (protocol === 'webdav:') { - const imgRegex = /.(jpg|jpeg|gif|png)$/i; - const isImage = imgRegex.test(path); + const supportedImageExtensions = ['jpg', 'JPG', 'jpeg', 'JPEG', 'gif', 'GIF', 'png', 'PNG']; + const isImage = supportedImageExtensions.some(ext => path.includes(ext)); const prefix = isImage ? 'images/stencil/original/content' : 'content' return [cdnUrl, prefix, path].join('/'); }