refactor: Clean up code by removing unnecessary whitespace and improving readability
This commit is contained in:
@@ -1,32 +1,27 @@
|
||||
import 'dart:io';
|
||||
import '../lib/services/trip_image_service.dart';
|
||||
import 'package:travel_mate/services/trip_image_service.dart';
|
||||
|
||||
/// Script utilitaire pour nettoyer les images inutilisées
|
||||
/// À exécuter manuellement si nécessaire
|
||||
void main() async {
|
||||
|
||||
try {
|
||||
final tripImageService = TripImageService();
|
||||
|
||||
|
||||
// Remplacez par votre ID utilisateur
|
||||
// Vous pouvez le récupérer depuis Firebase Auth dans votre app
|
||||
const userId = 'YOUR_USER_ID_HERE';
|
||||
|
||||
|
||||
if (userId == 'YOUR_USER_ID_HERE') {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final stats = await tripImageService.getImageStatistics(userId);
|
||||
|
||||
|
||||
|
||||
if (stats['tripsWithImages'] > 0) {
|
||||
await tripImageService.cleanupUnusedImages(userId);
|
||||
|
||||
|
||||
final newStats = await tripImageService.getImageStatistics(userId);
|
||||
} else {
|
||||
}
|
||||
|
||||
|
||||
} else {}
|
||||
} catch (e) {
|
||||
exit(1);
|
||||
}
|
||||
@@ -42,4 +37,4 @@ Instructions d'utilisation:
|
||||
4. Récupérez votre User ID affiché dans la console
|
||||
5. Remplacez 'YOUR_USER_ID_HERE' par votre ID dans ce script
|
||||
6. Exécutez: dart run scripts/cleanup_images.dart
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -1,48 +1,47 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import '../lib/firebase_options.dart';
|
||||
import 'package:travel_mate/firebase_options.dart';
|
||||
|
||||
/// Script de diagnostic pour analyser les images dans Firebase Storage
|
||||
void main() async {
|
||||
|
||||
try {
|
||||
// Initialiser Firebase
|
||||
await Firebase.initializeApp(
|
||||
options: DefaultFirebaseOptions.currentPlatform,
|
||||
);
|
||||
|
||||
|
||||
final storage = FirebaseStorage.instance;
|
||||
|
||||
|
||||
final listResult = await storage.ref('trip_images').listAll();
|
||||
|
||||
|
||||
if (listResult.items.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
final Map<String, List<Map<String, dynamic>>> locationGroups = {};
|
||||
|
||||
|
||||
for (int i = 0; i < listResult.items.length; i++) {
|
||||
final item = listResult.items[i];
|
||||
final fileName = item.name;
|
||||
|
||||
|
||||
|
||||
try {
|
||||
// Récupérer les métadonnées
|
||||
final metadata = await item.getMetadata();
|
||||
final customMeta = metadata.customMetadata ?? {};
|
||||
|
||||
|
||||
final location = customMeta['location'] ?? 'Inconnue';
|
||||
final normalizedLocation = customMeta['normalizedLocation'] ?? 'Non définie';
|
||||
final normalizedLocation =
|
||||
customMeta['normalizedLocation'] ?? 'Non définie';
|
||||
final source = customMeta['source'] ?? 'Inconnue';
|
||||
final uploadedAt = customMeta['uploadedAt'] ?? 'Inconnue';
|
||||
|
||||
|
||||
|
||||
// Récupérer l'URL de téléchargement
|
||||
final downloadUrl = await item.getDownloadURL();
|
||||
|
||||
|
||||
// Grouper par location normalisée
|
||||
final groupKey = normalizedLocation != 'Non définie' ? normalizedLocation : location.toLowerCase();
|
||||
final groupKey = normalizedLocation != 'Non définie'
|
||||
? normalizedLocation
|
||||
: location.toLowerCase();
|
||||
if (!locationGroups.containsKey(groupKey)) {
|
||||
locationGroups[groupKey] = [];
|
||||
}
|
||||
@@ -53,14 +52,12 @@ void main() async {
|
||||
'uploadedAt': uploadedAt,
|
||||
'downloadUrl': downloadUrl,
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
|
||||
// Essayer de deviner la location depuis le nom du fichier
|
||||
final parts = fileName.split('_');
|
||||
if (parts.length >= 2) {
|
||||
final guessedLocation = parts.take(parts.length - 1).join('_');
|
||||
|
||||
|
||||
if (!locationGroups.containsKey(guessedLocation)) {
|
||||
locationGroups[guessedLocation] = [];
|
||||
}
|
||||
@@ -73,30 +70,24 @@ void main() async {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Analyser les doublons
|
||||
|
||||
|
||||
int totalDuplicates = 0;
|
||||
for (final entry in locationGroups.entries) {
|
||||
final location = entry.key;
|
||||
final images = entry.value;
|
||||
|
||||
|
||||
if (images.length > 1) {
|
||||
totalDuplicates += images.length - 1;
|
||||
|
||||
|
||||
for (int i = 0; i < images.length; i++) {
|
||||
final image = images[i];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {}
|
||||
}
|
||||
|
||||
|
||||
if (totalDuplicates > 0) {
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (totalDuplicates > 0) {}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user