mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Corrently handle E2EE dirs in dir picker
This commit is contained in:
parent
cc9c8d7b60
commit
2645c7f977
3 changed files with 24 additions and 7 deletions
|
@ -8,7 +8,7 @@ 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 {
|
||||||
LsDirBlocItem(this.file, this.children);
|
LsDirBlocItem(this.file, this.isE2ee, this.children);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
toString({bool isDeep = false}) {
|
toString({bool isDeep = false}) {
|
||||||
|
@ -41,6 +41,7 @@ class LsDirBlocItem with EquatableMixin {
|
||||||
];
|
];
|
||||||
|
|
||||||
final File file;
|
final File file;
|
||||||
|
final bool isE2ee;
|
||||||
|
|
||||||
/// Child directories under this directory
|
/// Child directories under this directory
|
||||||
///
|
///
|
||||||
|
@ -183,13 +184,17 @@ class LsDirBloc extends Bloc<LsDirBlocEvent, LsDirBlocState> {
|
||||||
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, false, children));
|
||||||
} on ApiException catch (e) {
|
} on ApiException catch (e) {
|
||||||
if (e.response.statusCode == 404) {
|
if (e.response.statusCode == 404) {
|
||||||
// this could happen when the server db contains dangling entries
|
// this could happen when the server db contains dangling entries
|
||||||
_log.warning(
|
_log.warning(
|
||||||
"[call] HTTP404 error while listing dir: ${logFilename(f.path)}");
|
"[call] HTTP404 error while listing dir: ${logFilename(f.path)}");
|
||||||
removes.add(f);
|
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 {
|
} else {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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/exception_util.dart' as exception_util;
|
||||||
import 'package:nc_photos/k.dart' as k;
|
import 'package:nc_photos/k.dart' as k;
|
||||||
import 'package:nc_photos/snack_bar_manager.dart';
|
import 'package:nc_photos/snack_bar_manager.dart';
|
||||||
|
import 'package:nc_photos/theme.dart';
|
||||||
import 'package:path/path.dart' as path_lib;
|
import 'package:path/path.dart' as path_lib;
|
||||||
|
|
||||||
class DirPicker extends StatefulWidget {
|
class DirPicker extends StatefulWidget {
|
||||||
|
@ -41,7 +42,7 @@ class DirPickerState extends State<DirPicker> {
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_root = LsDirBlocItem(File(path: _rootDir), []);
|
_root = LsDirBlocItem(File(path: _rootDir), false, []);
|
||||||
_initBloc();
|
_initBloc();
|
||||||
if (widget.initialPicks != null) {
|
if (widget.initialPicks != null) {
|
||||||
_picks.addAll(widget.initialPicks!);
|
_picks.addAll(widget.initialPicks!);
|
||||||
|
@ -127,7 +128,7 @@ class DirPickerState extends State<DirPicker> {
|
||||||
context, state.items[index - (isTopLevel ? 0 : 1)]);
|
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),
|
itemCount: state.items.length + (isTopLevel ? 0 : 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -135,7 +136,7 @@ class DirPickerState extends State<DirPicker> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildItem(BuildContext context, LsDirBlocItem item) {
|
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);
|
final pickState = _isItemPicked(item);
|
||||||
|
|
||||||
IconData? iconData;
|
IconData? iconData;
|
||||||
|
@ -158,9 +159,12 @@ class DirPickerState extends State<DirPicker> {
|
||||||
: Icons.radio_button_unchecked;
|
: Icons.radio_button_unchecked;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (item.isE2ee) {
|
||||||
|
iconData = Icons.lock_outlined;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||||
dense: true,
|
dense: true,
|
||||||
leading: canPick
|
leading: canPick
|
||||||
? IconButton(
|
? IconButton(
|
||||||
|
@ -181,14 +185,16 @@ class DirPickerState extends State<DirPicker> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: const IconButton(
|
: IconButton(
|
||||||
icon: Icon(null),
|
icon: Icon(iconData),
|
||||||
|
color: AppTheme.getUnfocusedIconColor(context),
|
||||||
onPressed: null,
|
onPressed: null,
|
||||||
),
|
),
|
||||||
title: Text(item.file.filename),
|
title: Text(item.file.filename),
|
||||||
trailing: item.children?.isNotEmpty == true
|
trailing: item.children?.isNotEmpty == true
|
||||||
? const Icon(Icons.arrow_forward_ios)
|
? const Icon(Icons.arrow_forward_ios)
|
||||||
: null,
|
: null,
|
||||||
|
textColor: item.isE2ee ? AppTheme.getUnfocusedIconColor(context) : null,
|
||||||
onTap: item.children?.isNotEmpty == true
|
onTap: item.children?.isNotEmpty == true
|
||||||
? () {
|
? () {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -41,6 +41,7 @@ void main() {
|
||||||
path: "remote.php/dav/files/admin/d1",
|
path: "remote.php/dav/files/admin/d1",
|
||||||
isCollection: true,
|
isCollection: true,
|
||||||
),
|
),
|
||||||
|
false,
|
||||||
null,
|
null,
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
@ -62,6 +63,7 @@ void main() {
|
||||||
path: "remote.php/dav/files/admin/d1/d2-1",
|
path: "remote.php/dav/files/admin/d1/d2-1",
|
||||||
isCollection: true,
|
isCollection: true,
|
||||||
),
|
),
|
||||||
|
false,
|
||||||
null,
|
null,
|
||||||
),
|
),
|
||||||
LsDirBlocItem(
|
LsDirBlocItem(
|
||||||
|
@ -69,6 +71,7 @@ void main() {
|
||||||
path: "remote.php/dav/files/admin/d1/d2-2",
|
path: "remote.php/dav/files/admin/d1/d2-2",
|
||||||
isCollection: true,
|
isCollection: true,
|
||||||
),
|
),
|
||||||
|
false,
|
||||||
null,
|
null,
|
||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
|
@ -104,12 +107,14 @@ void main() {
|
||||||
path: "remote.php/dav/files/admin/d1",
|
path: "remote.php/dav/files/admin/d1",
|
||||||
isCollection: true,
|
isCollection: true,
|
||||||
),
|
),
|
||||||
|
false,
|
||||||
[
|
[
|
||||||
LsDirBlocItem(
|
LsDirBlocItem(
|
||||||
File(
|
File(
|
||||||
path: "remote.php/dav/files/admin/d1/d2-1",
|
path: "remote.php/dav/files/admin/d1/d2-1",
|
||||||
isCollection: true,
|
isCollection: true,
|
||||||
),
|
),
|
||||||
|
false,
|
||||||
null,
|
null,
|
||||||
),
|
),
|
||||||
LsDirBlocItem(
|
LsDirBlocItem(
|
||||||
|
@ -117,6 +122,7 @@ void main() {
|
||||||
path: "remote.php/dav/files/admin/d1/d2-2",
|
path: "remote.php/dav/files/admin/d1/d2-2",
|
||||||
isCollection: true,
|
isCollection: true,
|
||||||
),
|
),
|
||||||
|
false,
|
||||||
null,
|
null,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in a new issue