nc-photos/lib/use_case/scan_missing_metadata.dart

33 lines
1 KiB
Dart
Raw Normal View History

2021-04-10 06:28:12 +02:00
import 'package:nc_photos/account.dart';
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/entity/file_util.dart' as file_util;
2021-10-26 16:44:33 +02:00
import 'package:nc_photos/exception_event.dart';
2021-04-10 06:28:12 +02:00
import 'package:nc_photos/use_case/scan_dir.dart';
class ScanMissingMetadata {
ScanMissingMetadata(this.fileRepo);
/// List all files that support metadata but yet having one under a dir
/// recursively
///
/// Dirs with a .nomedia/.noimage file will be ignored. The returned stream
2021-10-26 16:44:33 +02:00
/// would emit either File data or ExceptionEvent
2021-04-10 06:28:12 +02:00
Stream<dynamic> call(Account account, File root) async* {
final dataStream = ScanDir(fileRepo)(account, root);
await for (final d in dataStream) {
2021-10-26 16:44:33 +02:00
if (d is ExceptionEvent) {
2021-04-10 06:28:12 +02:00
yield d;
continue;
}
final missingMetadata = (d as List<File>).where((element) =>
2021-10-26 20:54:48 +02:00
file_util.isSupportedImageFormat(element) &&
element.metadata == null);
2021-04-10 06:28:12 +02:00
for (final f in missingMetadata) {
yield f;
}
}
}
final FileRepo fileRepo;
}