feat(ViteAssetExtension): Améliore la gestion des assets et ajoute la détection de bot.
```
This commit is contained in:
Serreau Jovann
2026-01-22 22:17:32 +01:00
parent bbf508ff09
commit ccf1c3c042
2 changed files with 82 additions and 52 deletions

View File

@@ -1,34 +1,46 @@
import './reserve.scss';
import * as Sentry from "@sentry/browser";
import {UtmEvent,UtmAccount} from "./tools/UtmEvent.js";
import * as Turbo from "@hotwired/turbo"
// On ne fait plus d'import statique de Sentry ici
import {UtmEvent, UtmAccount} from "./tools/UtmEvent.js";
import * as Turbo from "@hotwired/turbo";
// --- INITIALISATION SENTRY ---
Sentry.init({
dsn: "https://803814be6540031b1c37bf92ba9c0f79@sentry.esy-web.dev/24",
tunnel: "/sentry-tunnel",
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
});
// --- INITIALISATION SENTRY (OPTIMISÉE BOT/LIGHTHOUSE) ---
const initSentry = async () => {
// On vérifie si on n'est pas un bot (la variable est passée par le PHP/Twig ou détectée en JS)
const isBot = /bot|googlebot|crawler|spider|robot|crawling|lighthouse/i.test(navigator.userAgent);
if (!isBot) {
try {
// Import dynamique : Le code de Sentry n'est téléchargé QUE si on entre ici
const Sentry = await import("@sentry/browser");
Sentry.init({
dsn: "https://803814be6540031b1c37bf92ba9c0f79@sentry.esy-web.dev/24",
tunnel: "/sentry-tunnel",
integrations: [Sentry.browserTracingIntegration()],
tracesSampleRate: 1.0,
});
} catch (e) {
}
}
};
// --- LOGIQUE DU REDIRECT ---
const initAutoRedirect = () => {
const container = document.getElementById('payment-check-container');
if (container && container.dataset.autoRedirect) {
const url = container.dataset.autoRedirect;
// On attend 5 secondes avant de rediriger via Turbo
setTimeout(() => {
// On vérifie que l'utilisateur est toujours sur la page de check
if (document.getElementById('payment-check-container')) {
Turbo.visit(url);
}
}, 10000);
}
}
// --- LOGIQUE DU LOADER TURBO ---
const initLoader = () => {
let loaderEl = document.getElementById('turbo-loader');
if (!loaderEl) {
loaderEl = document.createElement('div');
loaderEl.id = 'turbo-loader';
@@ -54,7 +66,6 @@ const initLoader = () => {
}, 300);
};
// --- ÉVÉNEMENTS TURBO (SANS BOUCLE INFINIE) ---
document.addEventListener("turbo:click", showLoader);
document.addEventListener("turbo:submit-start", showLoader);
document.addEventListener("turbo:load", hideLoader);
@@ -87,7 +98,6 @@ const initCatalogueSearch = () => {
const category = btn.getAttribute('data-filter').toLowerCase();
let count = 0;
// UI boutons
filters.forEach(f => {
f.classList.remove('bg-slate-900', 'text-white');
f.classList.add('bg-white', 'text-slate-500');
@@ -95,7 +105,6 @@ const initCatalogueSearch = () => {
btn.classList.add('bg-slate-900', 'text-white');
btn.classList.remove('bg-white', 'text-slate-500');
// Filtrage
products.forEach(item => {
const itemCat = item.getAttribute('data-category').toLowerCase();
if (category === 'all' || itemCat.includes(category)) {
@@ -115,13 +124,14 @@ const initCatalogueSearch = () => {
// --- INITIALISATION ---
document.addEventListener('DOMContentLoaded', () => {
initSentry(); // Appel asynchrone de Sentry
initLoader();
initMobileMenu();
initCatalogueSearch();
initAutoRedirect();
customElements.define('utm-event',UtmEvent)
customElements.define('utm-account',UtmAccount)
if (!customElements.get('utm-event')) customElements.define('utm-event', UtmEvent);
if (!customElements.get('utm-account')) customElements.define('utm-account', UtmAccount);
});
document.addEventListener('turbo:load', () => {
@@ -130,7 +140,6 @@ document.addEventListener('turbo:load', () => {
initAutoRedirect();
});
// Nettoyage avant cache pour éviter les bugs au retour arrière
document.addEventListener("turbo:before-cache", () => {
document.querySelectorAll('.product-item').forEach(i => i.style.display = 'block');
if (document.getElementById('empty-msg')) document.getElementById('empty-msg').classList.add('hidden');