Corrently handle E2EE dirs in dir picker

This commit is contained in:
Ming Ming 2022-05-16 17:54:48 +08:00
parent cc9c8d7b60
commit 2645c7f977
3 changed files with 24 additions and 7 deletions

View file

@ -8,7 +8,7 @@ import 'package:nc_photos/exception.dart';
import 'package:nc_photos/use_case/ls.dart';
class LsDirBlocItem with EquatableMixin {
LsDirBlocItem(this.file, this.children);
LsDirBlocItem(this.file, this.isE2ee, this.children);
@override
toString({bool isDeep = false}) {
@ -41,6 +41,7 @@ class LsDirBlocItem with EquatableMixin {
];
final File file;
final bool isE2ee;
/// Child directories under this directory
///
@ -183,13 +184,17 @@ class LsDirBloc extends Bloc<LsDirBlocEvent, LsDirBlocState> {
if (ev.depth > 1) {
children = await _query(ev.copyWith(root: f, depth: ev.depth - 1));
}
product.add(LsDirBlocItem(f, children));
product.add(LsDirBlocItem(f, false, children));
} on ApiException catch (e) {
if (e.response.statusCode == 404) {
// this could happen when the server db contains dangling entries
_log.warning(
"[call] HTTP404 error while listing dir: ${logFilename(f.path)}");
removes.add(f);
} else if (f.isCollection == true && e.response.statusCode == 403) {
// e2ee dir
_log.warning("[call] HTTP403 error, likely E2EE dir: ${f.path}");
product.add(LsDirBlocItem(f, true, []));
} else {
rethrow;
}

View file

@ -11,6 +11,7 @@ import 'package:nc_photos/entity/file_util.dart' as file_util;
import 'package:nc_photos/exception_util.dart' as exception_util;
import 'package:nc_photos/k.dart' as k;
import 'package:nc_photos/snack_bar_manager.dart';
import 'package:nc_photos/theme.dart';
import 'package:path/path.dart' as path_lib;
class DirPicker extends StatefulWidget {
@ -41,7 +42,7 @@ class DirPickerState extends State<DirPicker> {
@override
initState() {
super.initState();
_root = LsDirBlocItem(File(path: _rootDir), []);
_root = LsDirBlocItem(File(path: _rootDir), false, []);
_initBloc();
if (widget.initialPicks != null) {
_picks.addAll(widget.initialPicks!);
@ -127,7 +128,7 @@ class DirPickerState extends State<DirPicker> {
context, state.items[index - (isTopLevel ? 0 : 1)]);
}
},
separatorBuilder: (context, index) => const Divider(),
separatorBuilder: (context, index) => const Divider(height: 2),
itemCount: state.items.length + (isTopLevel ? 0 : 1),
),
),
@ -135,7 +136,7 @@ class DirPickerState extends State<DirPicker> {
}
Widget _buildItem(BuildContext context, LsDirBlocItem item) {
final canPick = widget.validator?.call(item.file) != false;
final canPick = !item.isE2ee && widget.validator?.call(item.file) != false;
final pickState = _isItemPicked(item);
IconData? iconData;
@ -158,9 +159,12 @@ class DirPickerState extends State<DirPicker> {
: Icons.radio_button_unchecked;
break;
}
} else if (item.isE2ee) {
iconData = Icons.lock_outlined;
}
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
dense: true,
leading: canPick
? IconButton(
@ -181,14 +185,16 @@ class DirPickerState extends State<DirPicker> {
}
},
)
: const IconButton(
icon: Icon(null),
: IconButton(
icon: Icon(iconData),
color: AppTheme.getUnfocusedIconColor(context),
onPressed: null,
),
title: Text(item.file.filename),
trailing: item.children?.isNotEmpty == true
? const Icon(Icons.arrow_forward_ios)
: null,
textColor: item.isE2ee ? AppTheme.getUnfocusedIconColor(context) : null,
onTap: item.children?.isNotEmpty == true
? () {
try {

View file

@ -41,6 +41,7 @@ void main() {
path: "remote.php/dav/files/admin/d1",
isCollection: true,
),
false,
null,
),
]),
@ -62,6 +63,7 @@ void main() {
path: "remote.php/dav/files/admin/d1/d2-1",
isCollection: true,
),
false,
null,
),
LsDirBlocItem(
@ -69,6 +71,7 @@ void main() {
path: "remote.php/dav/files/admin/d1/d2-2",
isCollection: true,
),
false,
null,
),
]),
@ -104,12 +107,14 @@ void main() {
path: "remote.php/dav/files/admin/d1",
isCollection: true,
),
false,
[
LsDirBlocItem(
File(
path: "remote.php/dav/files/admin/d1/d2-1",
isCollection: true,
),
false,
null,
),
LsDirBlocItem(
@ -117,6 +122,7 @@ void main() {
path: "remote.php/dav/files/admin/d1/d2-2",
isCollection: true,
),
false,
null,
),
],