Remove the prints

This commit is contained in:
Dayron
2025-11-03 15:30:20 +01:00
parent cb253831a0
commit 4836514223
7 changed files with 3 additions and 125 deletions

View File

@@ -11,20 +11,16 @@ class PlaceImageService {
/// Récupère l'URL de l'image d'un lieu depuis Google Places API
Future<String?> getPlaceImageUrl(String location) async {
print('PlaceImageService: Tentative de récupération d\'image pour: $location');
try {
// ÉTAPE 1: Vérifier d'abord si une image existe déjà dans le Storage
final existingUrl = await _checkExistingImage(location);
if (existingUrl != null) {
print('PlaceImageService: Image existante trouvée dans le Storage: $existingUrl');
return existingUrl;
}
print('PlaceImageService: Aucune image existante, recherche via Google Places API...');
if (_apiKey.isEmpty) {
print('PlaceImageService: Erreur - Google Maps API key manquante');
_errorService.logError('PlaceImageService', 'Google Maps API key manquante');
return null;
}
@@ -33,33 +29,27 @@ class PlaceImageService {
final searchTerms = _generateSearchTerms(location);
for (final searchTerm in searchTerms) {
print('PlaceImageService: Essai avec terme de recherche: $searchTerm');
// 1. Rechercher le lieu
final placeId = await _getPlaceIdForTerm(searchTerm);
if (placeId == null) continue;
print('PlaceImageService: Place ID trouvé: $placeId');
// 2. Récupérer les détails du lieu avec les photos
final photoReference = await _getPhotoReference(placeId);
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)
final imageUrl = await _downloadAndSaveImage(photoReference, location);
if (imageUrl != null) {
print('PlaceImageService: Image URL finale: $imageUrl');
return imageUrl;
}
}
print('PlaceImageService: Aucune image trouvée pour tous les termes de recherche');
return null;
} 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');
return null;
}
@@ -178,7 +168,6 @@ class PlaceImageService {
}
return null;
} catch (e) {
print('PlaceImageService: Erreur recherche avec type $type: $e');
return null;
}
}
@@ -205,7 +194,6 @@ class PlaceImageService {
}
return null;
} catch (e) {
print('PlaceImageService: Erreur recherche générale: $e');
return null;
}
}
@@ -296,7 +284,6 @@ class PlaceImageService {
'&photo_reference=$photoReference'
'&key=$_apiKey';
print('PlaceImageService: Téléchargement de l\'image: $imageUrl');
// Télécharger l'image
final response = await http.get(Uri.parse(imageUrl));
@@ -325,14 +312,11 @@ class PlaceImageService {
// Récupérer l'URL de téléchargement
final downloadUrl = await uploadTask.ref.getDownloadURL();
print('PlaceImageService: Image sauvegardée avec succès: $downloadUrl');
return downloadUrl;
} else {
print('PlaceImageService: Erreur HTTP ${response.statusCode} lors du téléchargement');
}
return null;
} catch (e) {
print('PlaceImageService: Erreur lors du téléchargement/sauvegarde: $e');
_errorService.logError('PlaceImageService', 'Erreur lors du téléchargement/sauvegarde: $e');
return null;
}
@@ -342,7 +326,6 @@ class PlaceImageService {
Future<String?> _checkExistingImage(String location) async {
try {
final normalizedLocation = _normalizeLocationName(location);
print('PlaceImageService: Recherche d\'image existante pour "$location" (normalisé: "$normalizedLocation")');
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)
if (storedNormalizedLocation != null && storedNormalizedLocation == normalizedLocation) {
final url = await item.getDownloadURL();
print('PlaceImageService: Image trouvée via normalizedLocation: $url');
return url;
}
@@ -364,7 +346,6 @@ class PlaceImageService {
final storedLocationNormalized = _normalizeLocationName(storedLocation);
if (storedLocationNormalized == normalizedLocation) {
final url = await item.getDownloadURL();
print('PlaceImageService: Image trouvée via location originale: $url');
return url;
}
}
@@ -375,21 +356,17 @@ class PlaceImageService {
if (fileName.toLowerCase().contains(normalizedLocation.toLowerCase())) {
try {
final url = await item.getDownloadURL();
print('PlaceImageService: Image trouvée via nom de fichier: $url');
return url;
} 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;
} catch (e) {
print('PlaceImageService: Erreur lors de la vérification d\'images existantes: $e');
return null;
}
}
@@ -406,7 +383,6 @@ class PlaceImageService {
/// Nettoie les images inutilisées (à appeler manuellement si nécessaire)
Future<void> cleanupUnusedImages(List<String> usedImageUrls) async {
try {
print('PlaceImageService: Nettoyage des images inutilisées...');
final listResult = await _storage.ref('trip_images').listAll();
int deletedCount = 0;
@@ -417,16 +393,13 @@ class PlaceImageService {
if (!usedImageUrls.contains(url)) {
await item.delete();
deletedCount++;
print('PlaceImageService: Image supprimée: ${item.name}');
}
} 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) {
print('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
Future<void> cleanupDuplicateImages() async {
try {
print('PlaceImageService: Nettoyage des images en doublon...');
final listResult = await _storage.ref('trip_images').listAll();
// Grouper les images par location normalisée
@@ -482,7 +454,6 @@ class PlaceImageService {
final images = entry.value;
if (images.length > 1) {
print('PlaceImageService: Doublons trouvés pour "$location": ${images.length} images');
// Trier par timestamp (garder le plus récent)
images.sort((a, b) {
@@ -496,19 +467,15 @@ class PlaceImageService {
try {
await images[i].delete();
deletedCount++;
print('PlaceImageService: Doublon supprimé: ${images[i].name}');
} 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) {
print('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)
Future<String?> getExistingImageUrl(String location) async {
try {
print('PlaceImageService: Recherche d\'image existante pour: $location');
final existingUrl = await _checkExistingImage(location);
if (existingUrl != null) {
print('PlaceImageService: Image existante trouvée: $existingUrl');
return existingUrl;
}
print('PlaceImageService: Aucune image existante trouvée pour: $location');
return null;
} 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');
return null;
}