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.
This commit is contained in:
98
scripts/simple_cleanup.dart
Normal file
98
scripts/simple_cleanup.dart
Normal file
@@ -0,0 +1,98 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user