diff --git a/lib/entity/share.dart b/lib/entity/share.dart index c452ab4b..7b9620c9 100644 --- a/lib/entity/share.dart +++ b/lib/entity/share.dart @@ -5,6 +5,7 @@ import 'package:nc_photos/entity/file.dart'; class Share with EquatableMixin { Share({ required this.id, + required this.path, required this.shareType, required this.shareWith, required this.shareWithDisplayName, @@ -14,6 +15,7 @@ class Share with EquatableMixin { toString() { return "$runtimeType {" "id: $id, " + "path: $path, " "shareType: $shareType, " "shareWith: $shareWith, " "shareWithDisplayName: $shareWithDisplayName, " @@ -23,12 +25,14 @@ class Share with EquatableMixin { @override get props => [ id, + path, shareType, shareWith, shareWithDisplayName, ]; final String id; + final String path; final int shareType; final String shareWith; final String shareWithDisplayName; @@ -41,6 +45,10 @@ class ShareRepo { Future> list(Account account, File file) => this.dataSrc.list(account, file); + /// See [ShareDataSource.listDir] + Future> listDir(Account account, File dir) => + this.dataSrc.listDir(account, dir); + /// See [ShareDataSource.create] Future create(Account account, File file, String shareWith) => this.dataSrc.create(account, file, shareWith); @@ -56,6 +64,9 @@ abstract class ShareDataSource { /// List all shares from a given file Future> list(Account account, File file); + /// List all shares from a given directory + Future> listDir(Account account, File dir); + /// Share a file/folder with a user Future create(Account account, File file, String shareWith); diff --git a/lib/entity/share/data_source.dart b/lib/entity/share/data_source.dart index 15b6b652..7f1f8ed0 100644 --- a/lib/entity/share/data_source.dart +++ b/lib/entity/share/data_source.dart @@ -15,16 +15,17 @@ class ShareRemoteDataSource implements ShareDataSource { final response = await Api(account).ocs().filesSharing().shares().get( path: file.strippedPath, ); - if (!response.isGood) { - _log.severe("[list] Failed requesting server: $response"); - throw ApiException( - response: response, - message: "Failed communicating with server: ${response.statusCode}"); - } + return _onListResult(response); + } - final json = jsonDecode(response.body); - final List dataJson = json["ocs"]["data"].cast(); - return _ShareParser().parseList(dataJson); + @override + listDir(Account account, File dir) async { + _log.info("[listDir] ${dir.path}"); + final response = await Api(account).ocs().filesSharing().shares().get( + path: dir.strippedPath, + subfiles: true, + ); + return _onListResult(response); } @override @@ -60,6 +61,19 @@ class ShareRemoteDataSource implements ShareDataSource { } } + List _onListResult(Response response) { + if (!response.isGood) { + _log.severe("[_onListResult] Failed requesting server: $response"); + throw ApiException( + response: response, + message: "Failed communicating with server: ${response.statusCode}"); + } + + final json = jsonDecode(response.body); + final List dataJson = json["ocs"]["data"].cast(); + return _ShareParser().parseList(dataJson); + } + static final _log = Logger("entity.share.data_source.ShareRemoteDataSource"); } @@ -79,6 +93,7 @@ class _ShareParser { Share parseSingle(JsonObj json) { return Share( id: json["id"], + path: json["path"], shareType: json["share_type"], shareWith: json["share_with"], shareWithDisplayName: json["share_with_displayname"],