nc-photos/app/lib/use_case/scan_missing_metadata.dart

51 lines
1.4 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';
import 'package:nc_photos/use_case/ls.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
///
/// The returned stream would emit either File data or ExceptionEvent
///
/// If [isRecursive] is true, [root] and its sub dirs will be listed,
/// otherwise only [root] will be listed. Default to true
Stream<dynamic> call(
Account account,
File root, {
bool isRecursive = true,
}) async* {
if (isRecursive) {
yield* _doRecursive(account, root);
} else {
yield* _doSingle(account, root);
}
}
Stream<dynamic> _doRecursive(Account account, File root) async* {
2021-04-10 06:28:12 +02:00
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;
}
2022-08-20 12:35:59 +02:00
for (final f in (d as List<File>).where(file_util.isMissingMetadata)) {
2021-04-10 06:28:12 +02:00
yield f;
}
}
}
Stream<dynamic> _doSingle(Account account, File root) async* {
final files = await Ls(fileRepo)(account, root);
2022-08-20 12:35:59 +02:00
for (final f in files.where(file_util.isMissingMetadata)) {
yield f;
}
}
2021-04-10 06:28:12 +02:00
final FileRepo fileRepo;
}