Files
TravelMate/scripts/simple_cleanup.dart
Dayron e3dad39c4f feat: Add TripImageService for automatic trip image management
- Implemented TripImageService to load missing images for trips, reload images, and clean up unused images.
- Added functionality to get image statistics and clean up duplicate images.
- Created utility scripts for manual image cleanup and diagnostics in Firebase Storage.
- Introduced tests for image loading optimization and photo quality algorithms.
- Updated dependencies in pubspec.yaml and pubspec.lock for image handling.
2025-11-03 14:33:58 +01:00

98 lines
3.1 KiB
Dart
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_storage/firebase_storage.dart';
void main() async {
print("🧹 Début du nettoyage des doublons Londres...");
try {
await Firebase.initializeApp();
print("✅ Firebase initialisé");
final storage = FirebaseStorage.instance;
final ref = storage.ref().child('trip_images');
print("📋 Récupération de la liste des images...");
final result = await ref.listAll();
print("📊 Nombre total d'images: ${result.items.length}");
// Grouper les images par ville
Map<String, List<Reference>> imagesByCity = {};
for (var item in result.items) {
final name = item.name;
print("🖼️ Image trouvée: $name");
// Extraire la ville du nom de fichier
String city = 'unknown';
if (name.contains('_')) {
// Format: londres_timestamp.jpg ou london_timestamp.jpg
city = name.split('_')[0].toLowerCase();
}
if (!imagesByCity.containsKey(city)) {
imagesByCity[city] = [];
}
imagesByCity[city]!.add(item);
}
print("\n📍 Images par ville:");
for (var entry in imagesByCity.entries) {
print(" ${entry.key}: ${entry.value.length} image(s)");
}
// Focus sur Londres/London
final londonImages = <Reference>[];
londonImages.addAll(imagesByCity['londres'] ?? []);
londonImages.addAll(imagesByCity['london'] ?? []);
print("\n🏴󠁧󠁢󠁥󠁮󠁧󠁿 Images de Londres trouvées: ${londonImages.length}");
if (londonImages.length > 1) {
print("🔄 Suppression des doublons...");
// Trier par timestamp (garder la plus récente)
londonImages.sort((a, b) {
final timestampA = _extractTimestamp(a.name);
final timestampB = _extractTimestamp(b.name);
return timestampB.compareTo(timestampA); // Plus récent en premier
});
print("📅 Images triées par timestamp:");
for (var image in londonImages) {
final timestamp = _extractTimestamp(image.name);
print(" ${image.name} - $timestamp");
}
// Supprimer toutes sauf la première (plus récente)
for (int i = 1; i < londonImages.length; i++) {
print("🗑️ Suppression: ${londonImages[i].name}");
await londonImages[i].delete();
}
print("✅ Suppression terminée. Image conservée: ${londonImages[0].name}");
} else {
print(" Aucun doublon trouvé pour Londres");
}
print("\n🎉 Nettoyage terminé !");
} catch (e) {
print("❌ Erreur: $e");
}
}
int _extractTimestamp(String filename) {
try {
// Extraire le timestamp du nom de fichier
// Format: ville_timestamp.jpg
final parts = filename.split('_');
if (parts.length >= 2) {
final timestampPart = parts[1].split('.')[0]; // Enlever l'extension
return int.parse(timestampPart);
}
} catch (e) {
print("⚠️ Impossible d'extraire le timestamp de $filename");
}
return 0; // Timestamp par défaut
}