@bebranded/bb-contents 1.0.46-beta → 1.0.48-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bb-contents.js +36 -21
- package/package.json +1 -1
package/bb-contents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BeBranded Contents
|
|
3
3
|
* Contenus additionnels français pour Webflow
|
|
4
|
-
* @version 1.0.
|
|
4
|
+
* @version 1.0.48-beta
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
// Configuration
|
|
24
24
|
const config = {
|
|
25
|
-
version: '1.0.
|
|
26
|
-
debug:
|
|
25
|
+
version: '1.0.48-beta',
|
|
26
|
+
debug: false, // Debug désactivé
|
|
27
27
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
28
28
|
youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
|
|
29
29
|
i18n: {
|
|
@@ -175,14 +175,12 @@
|
|
|
175
175
|
checkYouTubeConfig: function() {
|
|
176
176
|
// Vérifier si la configuration a été définie après le chargement
|
|
177
177
|
if (this.config.youtubeEndpoint) {
|
|
178
|
-
console.log('[DEBUG] YouTube endpoint found:', this.config.youtubeEndpoint);
|
|
179
178
|
return true;
|
|
180
179
|
}
|
|
181
180
|
|
|
182
181
|
// Vérifier dans l'objet temporaire
|
|
183
182
|
if (window._bbContentsConfig && window._bbContentsConfig.youtubeEndpoint) {
|
|
184
183
|
this.config.youtubeEndpoint = window._bbContentsConfig.youtubeEndpoint;
|
|
185
|
-
console.log('[DEBUG] YouTube endpoint found in temp config:', this.config.youtubeEndpoint);
|
|
186
184
|
return true;
|
|
187
185
|
}
|
|
188
186
|
|
|
@@ -633,7 +631,6 @@
|
|
|
633
631
|
this.cleanCache();
|
|
634
632
|
|
|
635
633
|
const elements = scope.querySelectorAll('[bb-youtube-channel]');
|
|
636
|
-
console.log('[DEBUG] YouTube elements found:', elements.length);
|
|
637
634
|
if (elements.length === 0) return;
|
|
638
635
|
|
|
639
636
|
// Module détecté: youtube
|
|
@@ -666,7 +663,6 @@
|
|
|
666
663
|
// Vérifier la configuration au moment de l'initialisation
|
|
667
664
|
const endpoint = bbContents.checkYouTubeConfig() ? bbContents.config.youtubeEndpoint : null;
|
|
668
665
|
|
|
669
|
-
console.log('[DEBUG] YouTube element config:', {channelId, videoCount, allowShorts, language, endpoint});
|
|
670
666
|
|
|
671
667
|
if (!channelId) {
|
|
672
668
|
return;
|
|
@@ -678,7 +674,6 @@
|
|
|
678
674
|
const retries = parseInt(retryCount);
|
|
679
675
|
|
|
680
676
|
if (retries < 50) { // 50 * 100ms = 5 secondes max
|
|
681
|
-
console.log('[DEBUG] YouTube endpoint not configured yet, waiting... (attempt', retries + 1, ')');
|
|
682
677
|
element.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Configuration YouTube en cours...</div>';
|
|
683
678
|
element.setAttribute('data-youtube-retry-count', (retries + 1).toString());
|
|
684
679
|
|
|
@@ -689,7 +684,6 @@
|
|
|
689
684
|
return;
|
|
690
685
|
} else {
|
|
691
686
|
// Timeout après 5 secondes
|
|
692
|
-
console.log('[DEBUG] YouTube endpoint configuration timeout');
|
|
693
687
|
element.innerHTML = '<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626;"><strong>Configuration YouTube manquante</strong><br>Ajoutez dans le <head> :<br><code style="display: block; background: #f3f4f6; padding: 10px; margin: 10px 0; border-radius: 4px; font-family: monospace;"><script><br>bbContents.config.youtubeEndpoint = \'votre-worker-url\';<br></script></code></div>';
|
|
694
688
|
return;
|
|
695
689
|
}
|
|
@@ -723,27 +717,48 @@
|
|
|
723
717
|
const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}_${language}`;
|
|
724
718
|
const cachedData = this.cache.get(cacheKey);
|
|
725
719
|
|
|
726
|
-
if (cachedData) {
|
|
720
|
+
if (cachedData && cachedData.value) {
|
|
727
721
|
// Données YouTube récupérées du cache (économie API)
|
|
728
722
|
this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
|
|
729
723
|
return;
|
|
730
724
|
}
|
|
731
725
|
|
|
726
|
+
// Vérifier si un appel API est déjà en cours pour cette clé
|
|
727
|
+
const loadingKey = `loading_${cacheKey}`;
|
|
728
|
+
if (window[loadingKey]) {
|
|
729
|
+
// Attendre que l'autre appel se termine
|
|
730
|
+
const checkLoading = () => {
|
|
731
|
+
if (!window[loadingKey]) {
|
|
732
|
+
// L'autre appel est terminé, vérifier le cache
|
|
733
|
+
const newCachedData = this.cache.get(cacheKey);
|
|
734
|
+
if (newCachedData && newCachedData.value) {
|
|
735
|
+
this.generateYouTubeFeed(container, template, newCachedData.value, allowShorts, language);
|
|
736
|
+
} else {
|
|
737
|
+
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Erreur de chargement</div>';
|
|
738
|
+
}
|
|
739
|
+
} else {
|
|
740
|
+
setTimeout(checkLoading, 100);
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
checkLoading();
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// Marquer qu'un appel API est en cours
|
|
748
|
+
window[loadingKey] = true;
|
|
749
|
+
|
|
732
750
|
// Afficher un loader
|
|
733
751
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
|
|
734
752
|
|
|
735
753
|
// Appeler l'API via le Worker
|
|
736
|
-
console.log('[DEBUG] Fetching YouTube data from:', `${endpoint}?channelId=${channelId}&maxResults=${videoCount}&allowShorts=${allowShorts}`);
|
|
737
754
|
fetch(`${endpoint}?channelId=${channelId}&maxResults=${videoCount}&allowShorts=${allowShorts}`)
|
|
738
755
|
.then(response => {
|
|
739
|
-
console.log('[DEBUG] YouTube API response status:', response.status);
|
|
740
756
|
if (!response.ok) {
|
|
741
757
|
throw new Error(`HTTP ${response.status}`);
|
|
742
758
|
}
|
|
743
759
|
return response.json();
|
|
744
760
|
})
|
|
745
761
|
.then(data => {
|
|
746
|
-
console.log('[DEBUG] YouTube API data received:', data);
|
|
747
762
|
if (data.error) {
|
|
748
763
|
throw new Error(data.error.message || 'Erreur API YouTube');
|
|
749
764
|
}
|
|
@@ -753,22 +768,26 @@
|
|
|
753
768
|
// Données YouTube mises en cache pour 24h (économie API)
|
|
754
769
|
|
|
755
770
|
this.generateYouTubeFeed(container, template, data, allowShorts, language);
|
|
771
|
+
|
|
772
|
+
// Libérer le verrou
|
|
773
|
+
window[loadingKey] = false;
|
|
756
774
|
})
|
|
757
775
|
.catch(error => {
|
|
758
|
-
console.error('
|
|
776
|
+
console.error('Erreur API YouTube:', error);
|
|
759
777
|
// Erreur dans le module youtube
|
|
760
778
|
|
|
779
|
+
// Libérer le verrou en cas d'erreur
|
|
780
|
+
window[loadingKey] = false;
|
|
781
|
+
|
|
761
782
|
// En cas d'erreur, essayer de récupérer du cache même expiré
|
|
762
783
|
const expiredCache = localStorage.getItem(cacheKey);
|
|
763
784
|
if (expiredCache) {
|
|
764
785
|
try {
|
|
765
786
|
const cachedData = JSON.parse(expiredCache);
|
|
766
|
-
console.log('[DEBUG] Using expired cache:', cachedData);
|
|
767
787
|
// Utilisation du cache expiré en cas d'erreur API
|
|
768
788
|
this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
|
|
769
789
|
return;
|
|
770
790
|
} catch (e) {
|
|
771
|
-
console.error('[DEBUG] Cache parsing error:', e);
|
|
772
791
|
// Ignorer les erreurs de parsing
|
|
773
792
|
}
|
|
774
793
|
}
|
|
@@ -778,16 +797,13 @@
|
|
|
778
797
|
},
|
|
779
798
|
|
|
780
799
|
generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
|
|
781
|
-
|
|
782
|
-
if (!data.items || data.items.length === 0) {
|
|
783
|
-
console.log('[DEBUG] No videos found in data');
|
|
800
|
+
if (!data || !data.items || data.items.length === 0) {
|
|
784
801
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
|
|
785
802
|
return;
|
|
786
803
|
}
|
|
787
804
|
|
|
788
805
|
// Les vidéos sont déjà filtrées par l'API YouTube selon allowShorts
|
|
789
806
|
let videos = data.items;
|
|
790
|
-
console.log('[DEBUG] Processing', videos.length, 'videos');
|
|
791
807
|
// Vidéos reçues de l'API
|
|
792
808
|
|
|
793
809
|
// Vider le conteneur (en préservant les éléments marquee)
|
|
@@ -991,7 +1007,6 @@
|
|
|
991
1007
|
window.configureYouTube = function(endpoint) {
|
|
992
1008
|
if (bbContents) {
|
|
993
1009
|
bbContents.config.youtubeEndpoint = endpoint;
|
|
994
|
-
console.log('[DEBUG] YouTube endpoint configured globally:', endpoint);
|
|
995
1010
|
// Réinitialiser les modules YouTube
|
|
996
1011
|
bbContents.reinit();
|
|
997
1012
|
}
|