Skip to content

Commit

Permalink
fix: properly settings thumbs extensions on media with @v4 keys
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Mar 14, 2024
1 parent 4ba5225 commit dfaf422
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/script/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit dfaf422

Please sign in to comment.