getResourcesInContainer function
Get the list of sub-containers and files in a container Adapted from getContainerList() in gurriny/indi/lib/models/common/rest_api.dart
Implementation
Future<({List<String> subDirs, List<String> files})> getResourcesInContainer(
String containerUrl,
) async {
// The trailing "/" is essential for a directory
final url = containerUrl.endsWith('/') ? containerUrl : '$containerUrl/';
final (:accessToken, :dPopToken) = await getTokensForResource(url, 'GET');
final profResponse = await http.get(
Uri.parse(url),
headers: <String, String>{
'Accept': '*/*',
'Authorization': 'DPoP $accessToken',
'Connection': 'keep-alive',
'DPoP': dPopToken,
},
);
if (profResponse.statusCode == 200) {
//debugPrint(profResponse.body.runtimeType as String); // String
// NB: rdflib-0.2.8 (dart) is not able to parse this but
// rdflib-7.0.0 (python) can parse it
//
// final g = Graph();
// g.parseTurtle(profResponse.body);
final (:subDirs, :files) = _parseGetContainerResponse(profResponse.body);
// debugPrint('SubDirs: |${subDirs.join(", ")}|');
// debugPrint('Files : |${files.join(", ")}|');
return (subDirs: subDirs, files: files);
} else if (profResponse.statusCode == 403) {
// If the server returned a 403 response,
// then throw a forbidden exception.
throw AccessForbiddenException('Access to resource denied!');
} else {
// If the server did not return a 200 or 403 response,
// then trow a fail exception.
throw AccessFailedException('Access to resource failed!');
}
}