fix: galerie sans retéléchargement, ZIP par parties, suppression de photo, miniatures, liens admin et slugs non devinables
- Galerie fête : ne remplace plus l'URL signée d'une image déjà affichée (egress ~10 Go/h par écran) - ZIP découpé en parties (300 photos / 100 Mo), liens directs sans blob en mémoire - Suppression d'une photo par l'admin (original + miniature), POST authentifié par admin_token - Miniatures 480 px générées côté client, ZIP et téléchargement gardent l'original - Token admin dans le fragment (#token=), nginx sans access_log sur /admin/, logs Docker bornés - Slug avec suffixe aléatoire de 6 hex pour les nouveaux événements Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+41
-4
@@ -16,6 +16,10 @@
|
||||
// événements à très fort trafic simultané.
|
||||
|
||||
const POLL_INTERVAL_MS = 25_000;
|
||||
// Les URLs signées durent 10 min (GALLERY_SIGNED_URL_TTL_SECONDS dans
|
||||
// public-gallery) : marge de 2 min pour qu'une image lazy démarre son
|
||||
// chargement avant expiration.
|
||||
const URL_REFRESH_AFTER_MS = 8 * 60_000;
|
||||
|
||||
const eventNameEl = document.getElementById("event-name");
|
||||
const eventMetaEl = document.getElementById("event-meta");
|
||||
@@ -78,6 +82,29 @@ function buildCaption(photo) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
function setPhotoSrc(img, url) {
|
||||
img.src = url;
|
||||
img.dataset.signedAt = String(Date.now());
|
||||
}
|
||||
|
||||
// Miniature (thumb_url) par défaut ; original si pas de miniature (photo
|
||||
// d'avant les miniatures) ou si elle échoue à charger (repli unique, cf.
|
||||
// onerror dans renderPolaroid).
|
||||
function showPhoto(img, photo) {
|
||||
img.dataset.original = photo.signed_url || "";
|
||||
if (!photo.thumb_url) img.dataset.fallback = "1";
|
||||
const url = img.dataset.fallback ? photo.signed_url : photo.thumb_url;
|
||||
if (url) setPhotoSrc(img, url);
|
||||
}
|
||||
|
||||
// Un nouveau src = nouveau token = nouveau téléchargement complet : on ne
|
||||
// le change que si l'image n'est pas déjà affichée.
|
||||
function needsFreshUrl(img, now) {
|
||||
if (img.complete && img.naturalWidth > 0) return false; // chargée : le navigateur garde l'image
|
||||
if (img.complete) return true; // pas de src, ou chargement en échec (URL expirée, réseau)
|
||||
return now - Number(img.dataset.signedAt) > URL_REFRESH_AFTER_MS; // lazy pas encore chargée
|
||||
}
|
||||
|
||||
function renderPolaroid(photo, { animate = false } = {}) {
|
||||
const li = document.createElement("li");
|
||||
li.className = "polaroid" + (animate ? " polaroid--dropping" : "");
|
||||
@@ -86,7 +113,13 @@ function renderPolaroid(photo, { animate = false } = {}) {
|
||||
|
||||
const img = document.createElement("img");
|
||||
img.className = "polaroid__photo";
|
||||
img.src = photo.signed_url || "";
|
||||
img.onerror = () => {
|
||||
if (img.dataset.fallback || !img.dataset.original) return;
|
||||
console.warn(`[galerie] miniature indisponible pour ${photo.id}, repli sur l'original`);
|
||||
img.dataset.fallback = "1";
|
||||
setPhotoSrc(img, img.dataset.original);
|
||||
};
|
||||
showPhoto(img, photo);
|
||||
img.alt = photo.nom_invite
|
||||
? `Photo envoyée par ${photo.nom_invite}`
|
||||
: "Photo envoyée par un invité";
|
||||
@@ -190,10 +223,14 @@ function renderGallery(data) {
|
||||
|
||||
photosDesc.forEach((photo, index) => {
|
||||
if (renderedIds.has(photo.id)) {
|
||||
// Déjà affichée : on rafraîchit juste l'URL signée (elle expire au
|
||||
// bout de 10 min), sans toucher au reste du DOM de la carte.
|
||||
// Déjà rendue : URL fraîche seulement si l'image n'est pas affichée
|
||||
// (sinon chaque poll retéléchargerait toute la galerie).
|
||||
const existing = gridEl.querySelector(`[data-photo-id="${photo.id}"] .polaroid__photo`);
|
||||
if (existing && photo.signed_url) existing.src = photo.signed_url;
|
||||
if (existing && photo.signed_url && needsFreshUrl(existing, Date.now())) {
|
||||
showPhoto(existing, photo);
|
||||
} else if (existing) {
|
||||
existing.dataset.original = photo.signed_url || ""; // repli éventuel avec un jeton frais
|
||||
}
|
||||
return;
|
||||
}
|
||||
const card = renderPolaroid(photo, { animate: true });
|
||||
|
||||
Reference in New Issue
Block a user