From e7d0fd206ad7fde61b9c32b96ec86e4c22a7e2d7 Mon Sep 17 00:00:00 2001 From: Ming Ming Date: Mon, 10 Jan 2022 20:02:52 +0800 Subject: [PATCH] Silently hide 404 dirs in LsDir --- lib/bloc/ls_dir.dart | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/bloc/ls_dir.dart b/lib/bloc/ls_dir.dart index 582dc711..cdbb5d4c 100644 --- a/lib/bloc/ls_dir.dart +++ b/lib/bloc/ls_dir.dart @@ -3,6 +3,7 @@ import 'package:equatable/equatable.dart'; import 'package:logging/logging.dart'; import 'package:nc_photos/account.dart'; import 'package:nc_photos/entity/file.dart'; +import 'package:nc_photos/exception.dart'; import 'package:nc_photos/use_case/ls.dart'; class LsDirBlocItem with EquatableMixin { @@ -174,12 +175,25 @@ class LsDirBloc extends Bloc { .toList(); _cache[ev.root.path] = files; } + final removes = []; for (final f in files) { - List? children; - if (ev.depth > 1) { - children = await _query(ev.copyWith(root: f, depth: ev.depth - 1)); + try { + List? children; + if (ev.depth > 1) { + children = await _query(ev.copyWith(root: f, depth: ev.depth - 1)); + } + product.add(LsDirBlocItem(f, children)); + } on ApiException catch (e) { + if (e.response.statusCode == 404) { + // this could happen when the server db contains dangling entries + removes.add(f); + } else { + rethrow; + } } - product.add(LsDirBlocItem(f, children)); + } + if (removes.isNotEmpty) { + files.removeWhere((f) => removes.contains(f)); } return product; }