getDocument method
Implementation
RequestAndParser<http.BaseResponse, File?> getDocument(String docPath,
{String? scope}) {
final rd = switch (kIsWeb) {
true => RequestData('/login'),
false => RequestData(
_getDocFromHash_r,
json: {
'docPath': docPath,
},
returnsBinary: true,
)
};
parser(http.BaseResponse _res) async {
final res = _res.forceRes();
if (res == null || res.statusCode ~/ 100 != 2)
return null;
else {
try {
final filename = docPath.split('/').last;
final s = (scope ?? '').trim();
final storedName =
s.isNotEmpty ? '$s/Dokus/$filename' : 'Dokus/$filename';
await API().local.storeDoc(res.bodyBytes, storedName);
return API().local.readDoc(storedName);
} catch (e) {
debugPrint("failed to load webimg: " + e.toString());
}
}
}
return RequestAndParser(rd: rd, parser: parser);
}