mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 01:06:21 +01:00
List shares for a dir
This commit is contained in:
parent
b1d37f7b73
commit
b9bf48c6ed
2 changed files with 35 additions and 9 deletions
|
@ -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<Share>> list(Account account, File file) =>
|
||||
this.dataSrc.list(account, file);
|
||||
|
||||
/// See [ShareDataSource.listDir]
|
||||
Future<List<Share>> listDir(Account account, File dir) =>
|
||||
this.dataSrc.listDir(account, dir);
|
||||
|
||||
/// See [ShareDataSource.create]
|
||||
Future<Share> 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<Share>> list(Account account, File file);
|
||||
|
||||
/// List all shares from a given directory
|
||||
Future<List<Share>> listDir(Account account, File dir);
|
||||
|
||||
/// Share a file/folder with a user
|
||||
Future<Share> create(Account account, File file, String shareWith);
|
||||
|
||||
|
|
|
@ -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<JsonObj> dataJson = json["ocs"]["data"].cast<JsonObj>();
|
||||
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<Share> _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<JsonObj> dataJson = json["ocs"]["data"].cast<JsonObj>();
|
||||
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"],
|
||||
|
|
Loading…
Reference in a new issue