@bebranded/bb-contents 1.1.2 → 1.1.4
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 +48 -14
- 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.1.
|
|
4
|
+
* @version 1.1.4
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
// Version du script
|
|
13
|
-
const BB_CONTENTS_VERSION = '1.1.
|
|
13
|
+
const BB_CONTENTS_VERSION = '1.1.4';
|
|
14
14
|
|
|
15
15
|
// Créer l'objet temporaire pour la configuration si il n'existe pas
|
|
16
16
|
if (!window._bbContentsConfig) {
|
|
@@ -2481,6 +2481,11 @@
|
|
|
2481
2481
|
if (!endpoint || typeof endpoint !== 'string') {
|
|
2482
2482
|
throw new Error('Endpoint YouTube invalide');
|
|
2483
2483
|
}
|
|
2484
|
+
// Validation URL stricte
|
|
2485
|
+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
|
|
2486
|
+
throw new Error('Endpoint YouTube doit être une URL valide');
|
|
2487
|
+
}
|
|
2488
|
+
// Validation que l'endpoint correspond à la configuration
|
|
2484
2489
|
if (bbContents.config.youtubeEndpoint && !endpoint.startsWith(bbContents.config.youtubeEndpoint)) {
|
|
2485
2490
|
throw new Error('Endpoint YouTube non autorisé');
|
|
2486
2491
|
}
|
|
@@ -2588,33 +2593,38 @@
|
|
|
2588
2593
|
if (data.error) {
|
|
2589
2594
|
throw new Error(data.error.message || 'Erreur API YouTube');
|
|
2590
2595
|
}
|
|
2591
|
-
return data.items || [];
|
|
2596
|
+
return { success: true, items: data.items || [] };
|
|
2592
2597
|
})
|
|
2593
2598
|
.catch(error => {
|
|
2594
|
-
// En cas d'erreur pour une chaîne, retourner un
|
|
2599
|
+
// En cas d'erreur pour une chaîne, retourner un objet avec success: false
|
|
2595
2600
|
// Les autres chaînes continueront à fonctionner
|
|
2596
|
-
return [];
|
|
2601
|
+
return { success: false, items: [] };
|
|
2597
2602
|
});
|
|
2598
2603
|
});
|
|
2599
2604
|
|
|
2600
|
-
return Promise.all(promises).then(
|
|
2605
|
+
return Promise.all(promises).then(allResults => {
|
|
2606
|
+
// Vérifier si toutes les chaînes ont échoué
|
|
2607
|
+
const allChannelsFailed = allResults.every(result => !result.success);
|
|
2608
|
+
|
|
2601
2609
|
// Fusionner tous les items de toutes les chaînes
|
|
2602
|
-
const mergedItems = [].concat(...
|
|
2610
|
+
const mergedItems = [].concat(...allResults.map(result => result.items));
|
|
2603
2611
|
|
|
2604
2612
|
// Trier par date (publishedAt) - du plus récent au plus ancien
|
|
2613
|
+
// Protection contre publishedAt manquant
|
|
2605
2614
|
mergedItems.sort((a, b) => {
|
|
2606
|
-
const dateA = new Date(a.snippet
|
|
2607
|
-
const dateB = new Date(b.snippet
|
|
2615
|
+
const dateA = new Date(a.snippet?.publishedAt || 0);
|
|
2616
|
+
const dateB = new Date(b.snippet?.publishedAt || 0);
|
|
2608
2617
|
return dateB - dateA;
|
|
2609
2618
|
});
|
|
2610
2619
|
|
|
2611
|
-
// Retourner dans le format attendu
|
|
2620
|
+
// Retourner dans le format attendu avec flag d'erreur
|
|
2612
2621
|
return {
|
|
2613
2622
|
items: mergedItems,
|
|
2614
2623
|
pageInfo: {
|
|
2615
2624
|
totalResults: mergedItems.length,
|
|
2616
2625
|
resultsPerPage: mergedItems.length
|
|
2617
|
-
}
|
|
2626
|
+
},
|
|
2627
|
+
allChannelsFailed: allChannelsFailed
|
|
2618
2628
|
};
|
|
2619
2629
|
});
|
|
2620
2630
|
},
|
|
@@ -2639,7 +2649,12 @@
|
|
|
2639
2649
|
|
|
2640
2650
|
generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
|
|
2641
2651
|
if (!data || !data.items || data.items.length === 0) {
|
|
2642
|
-
|
|
2652
|
+
// Distinguer "aucune vidéo" de "toutes les chaînes ont échoué"
|
|
2653
|
+
if (data && data.allChannelsFailed) {
|
|
2654
|
+
container.innerHTML = '<div style="padding: 20px; background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; color: #dc2626; text-align: center;"><strong>Erreur de chargement</strong><br>Impossible de récupérer les vidéos des chaînes YouTube</div>';
|
|
2655
|
+
} else {
|
|
2656
|
+
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
|
|
2657
|
+
}
|
|
2643
2658
|
return;
|
|
2644
2659
|
}
|
|
2645
2660
|
|
|
@@ -2658,7 +2673,13 @@
|
|
|
2658
2673
|
|
|
2659
2674
|
// Cloner le template pour chaque vidéo
|
|
2660
2675
|
videos.forEach(item => {
|
|
2661
|
-
|
|
2676
|
+
// Validation de videoId avant utilisation
|
|
2677
|
+
const videoId = item.id?.videoId;
|
|
2678
|
+
if (!videoId) {
|
|
2679
|
+
// Ignorer les vidéos sans ID valide
|
|
2680
|
+
return;
|
|
2681
|
+
}
|
|
2682
|
+
|
|
2662
2683
|
const snippet = item.snippet;
|
|
2663
2684
|
|
|
2664
2685
|
// Cloner le template
|
|
@@ -2803,8 +2824,11 @@
|
|
|
2803
2824
|
// Fonction pour décoder les entités HTML
|
|
2804
2825
|
decodeHtmlEntities: function(text) {
|
|
2805
2826
|
if (!text) return '';
|
|
2827
|
+
// Sécuriser en utilisant textContent d'abord pour éviter l'exécution de HTML
|
|
2828
|
+
const div = document.createElement('div');
|
|
2829
|
+
div.textContent = text;
|
|
2806
2830
|
const textarea = document.createElement('textarea');
|
|
2807
|
-
textarea.innerHTML =
|
|
2831
|
+
textarea.innerHTML = div.innerHTML;
|
|
2808
2832
|
return textarea.value;
|
|
2809
2833
|
},
|
|
2810
2834
|
|
|
@@ -2848,6 +2872,16 @@
|
|
|
2848
2872
|
// Méthode globale pour configurer YouTube après le chargement
|
|
2849
2873
|
window.configureYouTube = function(endpoint) {
|
|
2850
2874
|
if (bbContents) {
|
|
2875
|
+
// Validation de l'endpoint
|
|
2876
|
+
if (!endpoint || typeof endpoint !== 'string') {
|
|
2877
|
+
console.error('bb-contents: Endpoint YouTube invalide');
|
|
2878
|
+
return;
|
|
2879
|
+
}
|
|
2880
|
+
// Validation URL (doit commencer par http:// ou https://)
|
|
2881
|
+
if (!endpoint.startsWith('http://') && !endpoint.startsWith('https://')) {
|
|
2882
|
+
console.error('bb-contents: Endpoint YouTube doit être une URL valide (http:// ou https://)');
|
|
2883
|
+
return;
|
|
2884
|
+
}
|
|
2851
2885
|
bbContents.config.youtubeEndpoint = endpoint;
|
|
2852
2886
|
// Réinitialiser les modules YouTube
|
|
2853
2887
|
bbContents.reinit();
|