Remove the prints
This commit is contained in:
@@ -45,14 +45,12 @@ class _TripCardState extends State<TripCard> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
print('TripCard: Tentative de chargement d\'image pour ${widget.trip.location}');
|
|
||||||
|
|
||||||
// D'abord vérifier si une image existe déjà dans le Storage
|
// D'abord vérifier si une image existe déjà dans le Storage
|
||||||
String? imageUrl = await _placeImageService.getExistingImageUrl(widget.trip.location);
|
String? imageUrl = await _placeImageService.getExistingImageUrl(widget.trip.location);
|
||||||
|
|
||||||
// Si aucune image n'existe, en télécharger une nouvelle
|
// Si aucune image n'existe, en télécharger une nouvelle
|
||||||
if (imageUrl == null) {
|
if (imageUrl == null) {
|
||||||
print('TripCard: Aucune image existante, téléchargement via Google Places...');
|
|
||||||
imageUrl = await _placeImageService.getPlaceImageUrl(widget.trip.location);
|
imageUrl = await _placeImageService.getPlaceImageUrl(widget.trip.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,14 +62,12 @@ class _TripCardState extends State<TripCard> {
|
|||||||
|
|
||||||
// Mettre à jour le voyage dans la base de données avec l'imageUrl
|
// Mettre à jour le voyage dans la base de données avec l'imageUrl
|
||||||
_updateTripWithImage(imageUrl);
|
_updateTripWithImage(imageUrl);
|
||||||
print('TripCard: Image chargée avec succès: $imageUrl');
|
|
||||||
} else {
|
} else {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoadingImage = false;
|
_isLoadingImage = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('TripCard: Erreur lors du chargement de l\'image: $e');
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_isLoadingImage = false;
|
_isLoadingImage = false;
|
||||||
@@ -91,10 +87,8 @@ class _TripCardState extends State<TripCard> {
|
|||||||
|
|
||||||
// Mettre à jour dans la base de données
|
// Mettre à jour dans la base de données
|
||||||
await _tripRepository.updateTrip(widget.trip.id!, updatedTrip);
|
await _tripRepository.updateTrip(widget.trip.id!, updatedTrip);
|
||||||
print('TripCard: Voyage mis à jour avec la nouvelle image dans la base de données');
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('TripCard: Erreur lors de la mise à jour du voyage: $e');
|
|
||||||
// En cas d'erreur, on continue sans échec - l'image reste affichée localement
|
// En cas d'erreur, on continue sans échec - l'image reste affichée localement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,20 +11,16 @@ class PlaceImageService {
|
|||||||
|
|
||||||
/// Récupère l'URL de l'image d'un lieu depuis Google Places API
|
/// Récupère l'URL de l'image d'un lieu depuis Google Places API
|
||||||
Future<String?> getPlaceImageUrl(String location) async {
|
Future<String?> getPlaceImageUrl(String location) async {
|
||||||
print('PlaceImageService: Tentative de récupération d\'image pour: $location');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ÉTAPE 1: Vérifier d'abord si une image existe déjà dans le Storage
|
// ÉTAPE 1: Vérifier d'abord si une image existe déjà dans le Storage
|
||||||
final existingUrl = await _checkExistingImage(location);
|
final existingUrl = await _checkExistingImage(location);
|
||||||
if (existingUrl != null) {
|
if (existingUrl != null) {
|
||||||
print('PlaceImageService: Image existante trouvée dans le Storage: $existingUrl');
|
|
||||||
return existingUrl;
|
return existingUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Aucune image existante, recherche via Google Places API...');
|
|
||||||
|
|
||||||
if (_apiKey.isEmpty) {
|
if (_apiKey.isEmpty) {
|
||||||
print('PlaceImageService: Erreur - Google Maps API key manquante');
|
|
||||||
_errorService.logError('PlaceImageService', 'Google Maps API key manquante');
|
_errorService.logError('PlaceImageService', 'Google Maps API key manquante');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -33,33 +29,27 @@ class PlaceImageService {
|
|||||||
final searchTerms = _generateSearchTerms(location);
|
final searchTerms = _generateSearchTerms(location);
|
||||||
|
|
||||||
for (final searchTerm in searchTerms) {
|
for (final searchTerm in searchTerms) {
|
||||||
print('PlaceImageService: Essai avec terme de recherche: $searchTerm');
|
|
||||||
|
|
||||||
// 1. Rechercher le lieu
|
// 1. Rechercher le lieu
|
||||||
final placeId = await _getPlaceIdForTerm(searchTerm);
|
final placeId = await _getPlaceIdForTerm(searchTerm);
|
||||||
if (placeId == null) continue;
|
if (placeId == null) continue;
|
||||||
|
|
||||||
print('PlaceImageService: Place ID trouvé: $placeId');
|
|
||||||
|
|
||||||
// 2. Récupérer les détails du lieu avec les photos
|
// 2. Récupérer les détails du lieu avec les photos
|
||||||
final photoReference = await _getPhotoReference(placeId);
|
final photoReference = await _getPhotoReference(placeId);
|
||||||
if (photoReference == null) continue;
|
if (photoReference == null) continue;
|
||||||
|
|
||||||
print('PlaceImageService: Photo référence trouvée: $photoReference');
|
|
||||||
|
|
||||||
// 3. Télécharger et sauvegarder l'image (seulement si pas d'image existante)
|
// 3. Télécharger et sauvegarder l'image (seulement si pas d'image existante)
|
||||||
final imageUrl = await _downloadAndSaveImage(photoReference, location);
|
final imageUrl = await _downloadAndSaveImage(photoReference, location);
|
||||||
if (imageUrl != null) {
|
if (imageUrl != null) {
|
||||||
print('PlaceImageService: Image URL finale: $imageUrl');
|
|
||||||
return imageUrl;
|
return imageUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Aucune image trouvée pour tous les termes de recherche');
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors de la récupération de l\'image: $e');
|
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la récupération de l\'image: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors de la récupération de l\'image: $e');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -178,7 +168,6 @@ class PlaceImageService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur recherche avec type $type: $e');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +194,6 @@ class PlaceImageService {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur recherche générale: $e');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -296,7 +284,6 @@ class PlaceImageService {
|
|||||||
'&photo_reference=$photoReference'
|
'&photo_reference=$photoReference'
|
||||||
'&key=$_apiKey';
|
'&key=$_apiKey';
|
||||||
|
|
||||||
print('PlaceImageService: Téléchargement de l\'image: $imageUrl');
|
|
||||||
|
|
||||||
// Télécharger l'image
|
// Télécharger l'image
|
||||||
final response = await http.get(Uri.parse(imageUrl));
|
final response = await http.get(Uri.parse(imageUrl));
|
||||||
@@ -325,14 +312,11 @@ class PlaceImageService {
|
|||||||
|
|
||||||
// Récupérer l'URL de téléchargement
|
// Récupérer l'URL de téléchargement
|
||||||
final downloadUrl = await uploadTask.ref.getDownloadURL();
|
final downloadUrl = await uploadTask.ref.getDownloadURL();
|
||||||
print('PlaceImageService: Image sauvegardée avec succès: $downloadUrl');
|
|
||||||
return downloadUrl;
|
return downloadUrl;
|
||||||
} else {
|
} else {
|
||||||
print('PlaceImageService: Erreur HTTP ${response.statusCode} lors du téléchargement');
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors du téléchargement/sauvegarde: $e');
|
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du téléchargement/sauvegarde: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors du téléchargement/sauvegarde: $e');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -342,7 +326,6 @@ class PlaceImageService {
|
|||||||
Future<String?> _checkExistingImage(String location) async {
|
Future<String?> _checkExistingImage(String location) async {
|
||||||
try {
|
try {
|
||||||
final normalizedLocation = _normalizeLocationName(location);
|
final normalizedLocation = _normalizeLocationName(location);
|
||||||
print('PlaceImageService: Recherche d\'image existante pour "$location" (normalisé: "$normalizedLocation")');
|
|
||||||
|
|
||||||
final listResult = await _storage.ref('trip_images').listAll();
|
final listResult = await _storage.ref('trip_images').listAll();
|
||||||
|
|
||||||
@@ -355,7 +338,6 @@ class PlaceImageService {
|
|||||||
// Méthode 1: Vérifier avec la location normalisée (nouvelles images)
|
// Méthode 1: Vérifier avec la location normalisée (nouvelles images)
|
||||||
if (storedNormalizedLocation != null && storedNormalizedLocation == normalizedLocation) {
|
if (storedNormalizedLocation != null && storedNormalizedLocation == normalizedLocation) {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
print('PlaceImageService: Image trouvée via normalizedLocation: $url');
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,7 +346,6 @@ class PlaceImageService {
|
|||||||
final storedLocationNormalized = _normalizeLocationName(storedLocation);
|
final storedLocationNormalized = _normalizeLocationName(storedLocation);
|
||||||
if (storedLocationNormalized == normalizedLocation) {
|
if (storedLocationNormalized == normalizedLocation) {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
print('PlaceImageService: Image trouvée via location originale: $url');
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,21 +356,17 @@ class PlaceImageService {
|
|||||||
if (fileName.toLowerCase().contains(normalizedLocation.toLowerCase())) {
|
if (fileName.toLowerCase().contains(normalizedLocation.toLowerCase())) {
|
||||||
try {
|
try {
|
||||||
final url = await item.getDownloadURL();
|
final url = await item.getDownloadURL();
|
||||||
print('PlaceImageService: Image trouvée via nom de fichier: $url');
|
|
||||||
return url;
|
return url;
|
||||||
} catch (urlError) {
|
} catch (urlError) {
|
||||||
print('PlaceImageService: Erreur récupération URL pour ${item.name}: $urlError');
|
_errorService.logError('PlaceImageService', 'Erreur lors de la récupération de l\'URL: $urlError');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Impossible de lire les métadonnées pour ${item.name}: $e');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Aucune image existante trouvée pour "$location"');
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors de la vérification d\'images existantes: $e');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,7 +383,6 @@ class PlaceImageService {
|
|||||||
/// Nettoie les images inutilisées (à appeler manuellement si nécessaire)
|
/// Nettoie les images inutilisées (à appeler manuellement si nécessaire)
|
||||||
Future<void> cleanupUnusedImages(List<String> usedImageUrls) async {
|
Future<void> cleanupUnusedImages(List<String> usedImageUrls) async {
|
||||||
try {
|
try {
|
||||||
print('PlaceImageService: Nettoyage des images inutilisées...');
|
|
||||||
final listResult = await _storage.ref('trip_images').listAll();
|
final listResult = await _storage.ref('trip_images').listAll();
|
||||||
int deletedCount = 0;
|
int deletedCount = 0;
|
||||||
|
|
||||||
@@ -417,16 +393,13 @@ class PlaceImageService {
|
|||||||
if (!usedImageUrls.contains(url)) {
|
if (!usedImageUrls.contains(url)) {
|
||||||
await item.delete();
|
await item.delete();
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
print('PlaceImageService: Image supprimée: ${item.name}');
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors de la suppression de ${item.name}: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Nettoyage terminé. $deletedCount images supprimées.');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors du nettoyage: $e');
|
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -434,7 +407,6 @@ class PlaceImageService {
|
|||||||
/// Nettoie spécifiquement les doublons d'images pour la même location
|
/// Nettoie spécifiquement les doublons d'images pour la même location
|
||||||
Future<void> cleanupDuplicateImages() async {
|
Future<void> cleanupDuplicateImages() async {
|
||||||
try {
|
try {
|
||||||
print('PlaceImageService: Nettoyage des images en doublon...');
|
|
||||||
final listResult = await _storage.ref('trip_images').listAll();
|
final listResult = await _storage.ref('trip_images').listAll();
|
||||||
|
|
||||||
// Grouper les images par location normalisée
|
// Grouper les images par location normalisée
|
||||||
@@ -482,7 +454,6 @@ class PlaceImageService {
|
|||||||
final images = entry.value;
|
final images = entry.value;
|
||||||
|
|
||||||
if (images.length > 1) {
|
if (images.length > 1) {
|
||||||
print('PlaceImageService: Doublons trouvés pour "$location": ${images.length} images');
|
|
||||||
|
|
||||||
// Trier par timestamp (garder le plus récent)
|
// Trier par timestamp (garder le plus récent)
|
||||||
images.sort((a, b) {
|
images.sort((a, b) {
|
||||||
@@ -496,19 +467,15 @@ class PlaceImageService {
|
|||||||
try {
|
try {
|
||||||
await images[i].delete();
|
await images[i].delete();
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
print('PlaceImageService: Doublon supprimé: ${images[i].name}');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur suppression ${images[i].name}: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors de la suppression du doublon: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Gardé: ${images[0].name} (plus récent)');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('PlaceImageService: Nettoyage des doublons terminé. $deletedCount images supprimées.');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors du nettoyage des doublons: $e');
|
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage des doublons: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors du nettoyage des doublons: $e');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -526,16 +493,12 @@ class PlaceImageService {
|
|||||||
/// Récupère uniquement l'URL d'une image existante dans le Storage (sans télécharger)
|
/// Récupère uniquement l'URL d'une image existante dans le Storage (sans télécharger)
|
||||||
Future<String?> getExistingImageUrl(String location) async {
|
Future<String?> getExistingImageUrl(String location) async {
|
||||||
try {
|
try {
|
||||||
print('PlaceImageService: Recherche d\'image existante pour: $location');
|
|
||||||
final existingUrl = await _checkExistingImage(location);
|
final existingUrl = await _checkExistingImage(location);
|
||||||
if (existingUrl != null) {
|
if (existingUrl != null) {
|
||||||
print('PlaceImageService: Image existante trouvée: $existingUrl');
|
|
||||||
return existingUrl;
|
return existingUrl;
|
||||||
}
|
}
|
||||||
print('PlaceImageService: Aucune image existante trouvée pour: $location');
|
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('PlaceImageService: Erreur lors de la recherche d\'image existante: $e');
|
|
||||||
_errorService.logError('PlaceImageService', 'Erreur lors de la recherche d\'image existante: $e');
|
_errorService.logError('PlaceImageService', 'Erreur lors de la recherche d\'image existante: $e');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,14 +35,12 @@ class TripImageService {
|
|||||||
|
|
||||||
/// Charge l'image pour un voyage spécifique
|
/// Charge l'image pour un voyage spécifique
|
||||||
Future<void> _loadImageForTrip(Trip trip) async {
|
Future<void> _loadImageForTrip(Trip trip) async {
|
||||||
print('TripImageService: Recherche d\'image pour ${trip.title} (${trip.location})');
|
|
||||||
|
|
||||||
// D'abord vérifier si une image existe déjà dans le Storage
|
// D'abord vérifier si une image existe déjà dans le Storage
|
||||||
String? imageUrl = await _placeImageService.getExistingImageUrl(trip.location);
|
String? imageUrl = await _placeImageService.getExistingImageUrl(trip.location);
|
||||||
|
|
||||||
// Si aucune image n'existe, en télécharger une nouvelle
|
// Si aucune image n'existe, en télécharger une nouvelle
|
||||||
if (imageUrl == null) {
|
if (imageUrl == null) {
|
||||||
print('TripImageService: Aucune image existante, téléchargement via Google Places...');
|
|
||||||
imageUrl = await _placeImageService.getPlaceImageUrl(trip.location);
|
imageUrl = await _placeImageService.getPlaceImageUrl(trip.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,9 +52,7 @@ class TripImageService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await _tripRepository.updateTrip(trip.id!, updatedTrip);
|
await _tripRepository.updateTrip(trip.id!, updatedTrip);
|
||||||
print('TripImageService: Image mise à jour pour ${trip.title}: $imageUrl');
|
|
||||||
} else {
|
} else {
|
||||||
print('TripImageService: Aucune image trouvée pour ${trip.title}');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,11 +132,8 @@ class TripImageService {
|
|||||||
/// Nettoie spécifiquement les doublons d'images
|
/// Nettoie spécifiquement les doublons d'images
|
||||||
Future<void> cleanupDuplicateImages() async {
|
Future<void> cleanupDuplicateImages() async {
|
||||||
try {
|
try {
|
||||||
print('TripImageService: Début du nettoyage des doublons...');
|
|
||||||
await _placeImageService.cleanupDuplicateImages();
|
await _placeImageService.cleanupDuplicateImages();
|
||||||
print('TripImageService: Nettoyage des doublons terminé');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('TripImageService: Erreur lors du nettoyage des doublons: $e');
|
|
||||||
_errorService.logError(
|
_errorService.logError(
|
||||||
'TripImageService',
|
'TripImageService',
|
||||||
'Erreur lors du nettoyage des doublons: $e',
|
'Erreur lors du nettoyage des doublons: $e',
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import '../lib/services/trip_image_service.dart';
|
|||||||
/// Script utilitaire pour nettoyer les images inutilisées
|
/// Script utilitaire pour nettoyer les images inutilisées
|
||||||
/// À exécuter manuellement si nécessaire
|
/// À exécuter manuellement si nécessaire
|
||||||
void main() async {
|
void main() async {
|
||||||
print('🧹 Script de nettoyage des images inutilisées');
|
|
||||||
print('=====================================');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final tripImageService = TripImageService();
|
final tripImageService = TripImageService();
|
||||||
@@ -15,36 +13,21 @@ void main() async {
|
|||||||
const userId = 'YOUR_USER_ID_HERE';
|
const userId = 'YOUR_USER_ID_HERE';
|
||||||
|
|
||||||
if (userId == 'YOUR_USER_ID_HERE') {
|
if (userId == 'YOUR_USER_ID_HERE') {
|
||||||
print('❌ Veuillez configurer votre userId dans le script');
|
|
||||||
print(' Récupérez votre ID depuis Firebase Auth dans l\'app');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('📊 Récupération des statistiques...');
|
|
||||||
final stats = await tripImageService.getImageStatistics(userId);
|
final stats = await tripImageService.getImageStatistics(userId);
|
||||||
|
|
||||||
print('Statistiques actuelles:');
|
|
||||||
print('- Voyages totaux: ${stats['totalTrips']}');
|
|
||||||
print('- Voyages avec image: ${stats['tripsWithImages']}');
|
|
||||||
print('- Voyages sans image: ${stats['tripsWithoutImages']}');
|
|
||||||
|
|
||||||
if (stats['tripsWithImages'] > 0) {
|
if (stats['tripsWithImages'] > 0) {
|
||||||
print('\n🧹 Nettoyage des images inutilisées...');
|
|
||||||
await tripImageService.cleanupUnusedImages(userId);
|
await tripImageService.cleanupUnusedImages(userId);
|
||||||
|
|
||||||
print('\n📊 Nouvelles statistiques...');
|
|
||||||
final newStats = await tripImageService.getImageStatistics(userId);
|
final newStats = await tripImageService.getImageStatistics(userId);
|
||||||
print('- Voyages totaux: ${newStats['totalTrips']}');
|
|
||||||
print('- Voyages avec image: ${newStats['tripsWithImages']}');
|
|
||||||
print('- Voyages sans image: ${newStats['tripsWithoutImages']}');
|
|
||||||
} else {
|
} else {
|
||||||
print('✅ Aucune image à nettoyer');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print('\n✅ Script terminé avec succès');
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('❌ Erreur lors du nettoyage: $e');
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,6 @@ import '../lib/firebase_options.dart';
|
|||||||
|
|
||||||
/// Script pour nettoyer les doublons d'images de Londres
|
/// Script pour nettoyer les doublons d'images de Londres
|
||||||
void main() async {
|
void main() async {
|
||||||
print('🧹 Nettoyage spécifique des doublons d\'images de Londres');
|
|
||||||
print('========================================================');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Initialiser Firebase
|
// Initialiser Firebase
|
||||||
@@ -14,20 +12,13 @@ void main() async {
|
|||||||
options: DefaultFirebaseOptions.currentPlatform,
|
options: DefaultFirebaseOptions.currentPlatform,
|
||||||
);
|
);
|
||||||
|
|
||||||
print('✅ Firebase initialisé');
|
|
||||||
|
|
||||||
final tripImageService = TripImageService();
|
final tripImageService = TripImageService();
|
||||||
|
|
||||||
print('🔍 Analyse et nettoyage des doublons...');
|
|
||||||
await tripImageService.cleanupDuplicateImages();
|
await tripImageService.cleanupDuplicateImages();
|
||||||
|
|
||||||
print('✅ Nettoyage terminé !');
|
|
||||||
print('');
|
|
||||||
print('🎯 Les doublons pour Londres (et autres destinations) ont été supprimés');
|
|
||||||
print(' Seule l\'image la plus récente pour chaque destination a été conservée');
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('❌ Erreur lors du nettoyage: $e');
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ import '../lib/firebase_options.dart';
|
|||||||
|
|
||||||
/// Script de diagnostic pour analyser les images dans Firebase Storage
|
/// Script de diagnostic pour analyser les images dans Firebase Storage
|
||||||
void main() async {
|
void main() async {
|
||||||
print('🔍 Diagnostic des images Firebase Storage');
|
|
||||||
print('=========================================');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Initialiser Firebase
|
// Initialiser Firebase
|
||||||
@@ -15,16 +13,12 @@ void main() async {
|
|||||||
|
|
||||||
final storage = FirebaseStorage.instance;
|
final storage = FirebaseStorage.instance;
|
||||||
|
|
||||||
print('📂 Analyse du dossier trip_images...');
|
|
||||||
final listResult = await storage.ref('trip_images').listAll();
|
final listResult = await storage.ref('trip_images').listAll();
|
||||||
|
|
||||||
if (listResult.items.isEmpty) {
|
if (listResult.items.isEmpty) {
|
||||||
print('❌ Aucune image trouvée dans trip_images/');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
print('📊 ${listResult.items.length} image(s) trouvée(s):');
|
|
||||||
print('');
|
|
||||||
|
|
||||||
final Map<String, List<Map<String, dynamic>>> locationGroups = {};
|
final Map<String, List<Map<String, dynamic>>> locationGroups = {};
|
||||||
|
|
||||||
@@ -32,7 +26,6 @@ void main() async {
|
|||||||
final item = listResult.items[i];
|
final item = listResult.items[i];
|
||||||
final fileName = item.name;
|
final fileName = item.name;
|
||||||
|
|
||||||
print('${i + 1}. Fichier: $fileName');
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Récupérer les métadonnées
|
// Récupérer les métadonnées
|
||||||
@@ -44,14 +37,9 @@ void main() async {
|
|||||||
final source = customMeta['source'] ?? 'Inconnue';
|
final source = customMeta['source'] ?? 'Inconnue';
|
||||||
final uploadedAt = customMeta['uploadedAt'] ?? 'Inconnue';
|
final uploadedAt = customMeta['uploadedAt'] ?? 'Inconnue';
|
||||||
|
|
||||||
print(' 📍 Location: $location');
|
|
||||||
print(' 🏷️ Normalized: $normalizedLocation');
|
|
||||||
print(' 📤 Source: $source');
|
|
||||||
print(' 📅 Upload: $uploadedAt');
|
|
||||||
|
|
||||||
// Récupérer l'URL de téléchargement
|
// Récupérer l'URL de téléchargement
|
||||||
final downloadUrl = await item.getDownloadURL();
|
final downloadUrl = await item.getDownloadURL();
|
||||||
print(' 🔗 URL: $downloadUrl');
|
|
||||||
|
|
||||||
// Grouper par location normalisée
|
// Grouper par location normalisée
|
||||||
final groupKey = normalizedLocation != 'Non définie' ? normalizedLocation : location.toLowerCase();
|
final groupKey = normalizedLocation != 'Non définie' ? normalizedLocation : location.toLowerCase();
|
||||||
@@ -67,13 +55,11 @@ void main() async {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(' ❌ Erreur lecture métadonnées: $e');
|
|
||||||
|
|
||||||
// Essayer de deviner la location depuis le nom du fichier
|
// Essayer de deviner la location depuis le nom du fichier
|
||||||
final parts = fileName.split('_');
|
final parts = fileName.split('_');
|
||||||
if (parts.length >= 2) {
|
if (parts.length >= 2) {
|
||||||
final guessedLocation = parts.take(parts.length - 1).join('_');
|
final guessedLocation = parts.take(parts.length - 1).join('_');
|
||||||
print(' 🤔 Location devinée: $guessedLocation');
|
|
||||||
|
|
||||||
if (!locationGroups.containsKey(guessedLocation)) {
|
if (!locationGroups.containsKey(guessedLocation)) {
|
||||||
locationGroups[guessedLocation] = [];
|
locationGroups[guessedLocation] = [];
|
||||||
@@ -88,12 +74,9 @@ void main() async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Analyser les doublons
|
// Analyser les doublons
|
||||||
print('🔍 Analyse des doublons par location:');
|
|
||||||
print('====================================');
|
|
||||||
|
|
||||||
int totalDuplicates = 0;
|
int totalDuplicates = 0;
|
||||||
for (final entry in locationGroups.entries) {
|
for (final entry in locationGroups.entries) {
|
||||||
@@ -101,31 +84,19 @@ void main() async {
|
|||||||
final images = entry.value;
|
final images = entry.value;
|
||||||
|
|
||||||
if (images.length > 1) {
|
if (images.length > 1) {
|
||||||
print('⚠️ DOUBLONS détectés pour "$location": ${images.length} images');
|
|
||||||
totalDuplicates += images.length - 1;
|
totalDuplicates += images.length - 1;
|
||||||
|
|
||||||
for (int i = 0; i < images.length; i++) {
|
for (int i = 0; i < images.length; i++) {
|
||||||
final image = images[i];
|
final image = images[i];
|
||||||
print(' ${i + 1}. ${image['fileName']} (${image['uploadedAt']})');
|
|
||||||
}
|
}
|
||||||
print('');
|
|
||||||
} else {
|
} else {
|
||||||
print('✅ "$location": 1 image (OK)');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print('📈 Résumé:');
|
|
||||||
print('- Total images: ${listResult.items.length}');
|
|
||||||
print('- Locations uniques: ${locationGroups.length}');
|
|
||||||
print('- Images en doublon: $totalDuplicates');
|
|
||||||
print('- Économie possible: ${totalDuplicates} images peuvent être supprimées');
|
|
||||||
|
|
||||||
if (totalDuplicates > 0) {
|
if (totalDuplicates > 0) {
|
||||||
print('');
|
|
||||||
print('💡 Suggestion: Utilisez la fonctionnalité de nettoyage pour supprimer les doublons');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('❌ Erreur lors du diagnostic: $e');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,26 +2,21 @@ import 'package:firebase_core/firebase_core.dart';
|
|||||||
import 'package:firebase_storage/firebase_storage.dart';
|
import 'package:firebase_storage/firebase_storage.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
print("🧹 Début du nettoyage des doublons Londres...");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Firebase.initializeApp();
|
await Firebase.initializeApp();
|
||||||
print("✅ Firebase initialisé");
|
|
||||||
|
|
||||||
final storage = FirebaseStorage.instance;
|
final storage = FirebaseStorage.instance;
|
||||||
final ref = storage.ref().child('trip_images');
|
final ref = storage.ref().child('trip_images');
|
||||||
|
|
||||||
print("📋 Récupération de la liste des images...");
|
|
||||||
final result = await ref.listAll();
|
final result = await ref.listAll();
|
||||||
|
|
||||||
print("📊 Nombre total d'images: ${result.items.length}");
|
|
||||||
|
|
||||||
// Grouper les images par ville
|
// Grouper les images par ville
|
||||||
Map<String, List<Reference>> imagesByCity = {};
|
Map<String, List<Reference>> imagesByCity = {};
|
||||||
|
|
||||||
for (var item in result.items) {
|
for (var item in result.items) {
|
||||||
final name = item.name;
|
final name = item.name;
|
||||||
print("🖼️ Image trouvée: $name");
|
|
||||||
|
|
||||||
// Extraire la ville du nom de fichier
|
// Extraire la ville du nom de fichier
|
||||||
String city = 'unknown';
|
String city = 'unknown';
|
||||||
@@ -36,9 +31,7 @@ void main() async {
|
|||||||
imagesByCity[city]!.add(item);
|
imagesByCity[city]!.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
print("\n📍 Images par ville:");
|
|
||||||
for (var entry in imagesByCity.entries) {
|
for (var entry in imagesByCity.entries) {
|
||||||
print(" ${entry.key}: ${entry.value.length} image(s)");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Focus sur Londres/London
|
// Focus sur Londres/London
|
||||||
@@ -46,10 +39,8 @@ void main() async {
|
|||||||
londonImages.addAll(imagesByCity['londres'] ?? []);
|
londonImages.addAll(imagesByCity['londres'] ?? []);
|
||||||
londonImages.addAll(imagesByCity['london'] ?? []);
|
londonImages.addAll(imagesByCity['london'] ?? []);
|
||||||
|
|
||||||
print("\n🏴 Images de Londres trouvées: ${londonImages.length}");
|
|
||||||
|
|
||||||
if (londonImages.length > 1) {
|
if (londonImages.length > 1) {
|
||||||
print("🔄 Suppression des doublons...");
|
|
||||||
|
|
||||||
// Trier par timestamp (garder la plus récente)
|
// Trier par timestamp (garder la plus récente)
|
||||||
londonImages.sort((a, b) {
|
londonImages.sort((a, b) {
|
||||||
@@ -58,27 +49,20 @@ void main() async {
|
|||||||
return timestampB.compareTo(timestampA); // Plus récent en premier
|
return timestampB.compareTo(timestampA); // Plus récent en premier
|
||||||
});
|
});
|
||||||
|
|
||||||
print("📅 Images triées par timestamp:");
|
|
||||||
for (var image in londonImages) {
|
for (var image in londonImages) {
|
||||||
final timestamp = _extractTimestamp(image.name);
|
final timestamp = _extractTimestamp(image.name);
|
||||||
print(" ${image.name} - $timestamp");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Supprimer toutes sauf la première (plus récente)
|
// Supprimer toutes sauf la première (plus récente)
|
||||||
for (int i = 1; i < londonImages.length; i++) {
|
for (int i = 1; i < londonImages.length; i++) {
|
||||||
print("🗑️ Suppression: ${londonImages[i].name}");
|
|
||||||
await londonImages[i].delete();
|
await londonImages[i].delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
print("✅ Suppression terminée. Image conservée: ${londonImages[0].name}");
|
|
||||||
} else {
|
} else {
|
||||||
print("ℹ️ Aucun doublon trouvé pour Londres");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
print("\n🎉 Nettoyage terminé !");
|
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("❌ Erreur: $e");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +76,6 @@ int _extractTimestamp(String filename) {
|
|||||||
return int.parse(timestampPart);
|
return int.parse(timestampPart);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("⚠️ Impossible d'extraire le timestamp de $filename");
|
|
||||||
}
|
}
|
||||||
return 0; // Timestamp par défaut
|
return 0; // Timestamp par défaut
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user