mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-24 07:54:42 +01:00
Silently hide 404 dirs in LsDir
This commit is contained in:
parent
5a02643e54
commit
e7d0fd206a
1 changed files with 18 additions and 4 deletions
|
@ -3,6 +3,7 @@ import 'package:equatable/equatable.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
|
import 'package:nc_photos/exception.dart';
|
||||||
import 'package:nc_photos/use_case/ls.dart';
|
import 'package:nc_photos/use_case/ls.dart';
|
||||||
|
|
||||||
class LsDirBlocItem with EquatableMixin {
|
class LsDirBlocItem with EquatableMixin {
|
||||||
|
@ -174,12 +175,25 @@ class LsDirBloc extends Bloc<LsDirBlocEvent, LsDirBlocState> {
|
||||||
.toList();
|
.toList();
|
||||||
_cache[ev.root.path] = files;
|
_cache[ev.root.path] = files;
|
||||||
}
|
}
|
||||||
|
final removes = <File>[];
|
||||||
for (final f in files) {
|
for (final f in files) {
|
||||||
|
try {
|
||||||
List<LsDirBlocItem>? children;
|
List<LsDirBlocItem>? children;
|
||||||
if (ev.depth > 1) {
|
if (ev.depth > 1) {
|
||||||
children = await _query(ev.copyWith(root: f, depth: ev.depth - 1));
|
children = await _query(ev.copyWith(root: f, depth: ev.depth - 1));
|
||||||
}
|
}
|
||||||
product.add(LsDirBlocItem(f, children));
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (removes.isNotEmpty) {
|
||||||
|
files.removeWhere((f) => removes.contains(f));
|
||||||
}
|
}
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue