From dfaf4227e1e6b08219dfd3c17932efc589791507 Mon Sep 17 00:00:00 2001 From: Leonardo Matos Date: Thu, 14 Mar 2024 17:54:46 -0300 Subject: [PATCH] fix: properly settings thumbs extensions on media with `@v4` keys https://github.com/ecomplus/admin/pull/779\#discussion_r1524749125 --- src/script/main.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/script/main.js b/src/script/main.js index 638eac05..0d05bac9 100644 --- a/src/script/main.js +++ b/src/script/main.js @@ -1525,16 +1525,22 @@ const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2 // based on product resource picture property // https://ecomstore.docs.apiary.io/#reference/products/product-object const picture = {} - if (/^@v[34]/.test(baseKey)) { + if (/^@v3/.test(baseKey)) { picture.zoom = { url: baseUrl + baseKey } - if ( - (/^@v4/.test(baseKey) && /\.thumbs\.[\w]+$/.test(baseKey)) || - (!/\.webp$/.test(baseKey)) - ) { + if (!/\.webp$/.test(baseKey)) { thumbSizes.forEach(({ thumb, path }) => { picture[thumb] = { url: baseUrl + path + baseKey + '.webp' } }) } + } else if (/^@v4/.test(baseKey)) { + picture.zoom = { url: baseUrl + baseKey } + if (/\.thumbs\.[\w]+$/.test(baseKey)) { + thumbSizes.forEach(({ thumb, path }) => { + picture[thumb] = { + url: baseUrl + path + baseKey.replace(/\.thumbs\.[\w]+$/, '.avif.webp') + } + }) + } } selectedImages.push(picture) } @@ -1688,7 +1694,7 @@ const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2 function (event) { if (!navigator.clipboard) { // Clipboard API not available - return; + return } const text = this.dataset && this.dataset.clipboardText try { @@ -1698,11 +1704,11 @@ const isApiv2 = Number(sessionStorage.getItem('api_version')) === 2 $('#uploads-copy-url span').text('Copiar Url') }, 1200) } catch (err) { - console.error("Failed to copy!", err); + console.error('Failed to copy!', err) } }, false - ); + ) } } catch (e) { // unexpected response