fix(controls): fix ReferenceError hdBtn and preserve query params in cache busting url

This commit is contained in:
kdeterme 2026-08-17 11:14:05 +02:00
parent 06b70a3129
commit 68d3e042dc

View file

@ -2094,6 +2094,18 @@ function updateRemarkCarouselActiveSlide(idx) {
} }
} }
function addTimestampToUrl(url) {
if (!url) return url;
try {
const u = new URL(url, window.location.origin);
u.searchParams.set('t', Date.now().toString());
return u.pathname + u.search + u.hash;
} catch (e) {
const sep = url.includes('?') ? '&' : '?';
return url.replace(/([&?]t=\d+)/, '') + sep + 't=' + Date.now();
}
}
async function rotateRemarkImage(imageId, triggerBtn) { async function rotateRemarkImage(imageId, triggerBtn) {
if (!imageId) return; if (!imageId) return;
@ -2117,26 +2129,20 @@ async function rotateRemarkImage(imageId, triggerBtn) {
}); });
const data = await response.json(); const data = await response.json();
if (data.success) { if (data.success) {
const timestamp = Date.now();
// Rafraîchir l'image active dans le carrousel si ouvert // Rafraîchir l'image active dans le carrousel si ouvert
const activeCarouselImg = document.querySelector('#remark-carousel-inner .carousel-item.active img'); const activeCarouselImg = document.querySelector('#remark-carousel-inner .carousel-item.active img');
if (activeCarouselImg) { if (activeCarouselImg) {
const cleanUrl = activeCarouselImg.src.split('?')[0]; activeCarouselImg.src = addTimestampToUrl(activeCarouselImg.src);
activeCarouselImg.src = `${cleanUrl}?t=${timestamp}`;
} }
// Rafraîchir toutes les vignettes et attributs data correspondants sur la page // Rafraîchir toutes les vignettes et attributs data correspondants sur la page
document.querySelectorAll(`img[data-image-id="${imageId}"]`).forEach(img => { document.querySelectorAll(`img[data-image-id="${imageId}"]`).forEach(img => {
const cleanThumb = img.src.split('?')[0]; img.src = addTimestampToUrl(img.src);
img.src = `${cleanThumb}?t=${timestamp}`;
if (img.dataset.fullUrl) { if (img.dataset.fullUrl) {
const cleanFull = img.dataset.fullUrl.split('?')[0]; img.dataset.fullUrl = addTimestampToUrl(img.dataset.fullUrl);
img.dataset.fullUrl = `${cleanFull}?t=${timestamp}`;
} }
if (img.dataset.thumbUrl) { if (img.dataset.thumbUrl) {
const cleanThumbData = img.dataset.thumbUrl.split('?')[0]; img.dataset.thumbUrl = addTimestampToUrl(img.dataset.thumbUrl);
img.dataset.thumbUrl = `${cleanThumbData}?t=${timestamp}`;
} }
}); });
@ -2144,8 +2150,9 @@ async function rotateRemarkImage(imageId, triggerBtn) {
if (currentRemarkCarouselPhotos && currentRemarkCarouselPhotos[currentRemarkCarouselIndex]) { if (currentRemarkCarouselPhotos && currentRemarkCarouselPhotos[currentRemarkCarouselIndex]) {
const curr = currentRemarkCarouselPhotos[currentRemarkCarouselIndex]; const curr = currentRemarkCarouselPhotos[currentRemarkCarouselIndex];
if (curr.imageId == imageId) { if (curr.imageId == imageId) {
curr.fullUrl = curr.fullUrl.split('?')[0] + `?t=${timestamp}`; curr.fullUrl = addTimestampToUrl(curr.fullUrl);
curr.thumbUrl = curr.thumbUrl.split('?')[0] + `?t=${timestamp}`; curr.thumbUrl = addTimestampToUrl(curr.thumbUrl);
const hdBtn = document.getElementById('remark-carousel-hd-btn');
if (hdBtn) hdBtn.href = curr.fullUrl; if (hdBtn) hdBtn.href = curr.fullUrl;
} }
} }