getDocument method

RequestAndParser<BaseResponse, File?> getDocument(
  1. String docPath
)

Implementation

RequestAndParser<http.BaseResponse, File?> getDocument(String docPath) {
  final rd = switch (kIsWeb) {
    true => RequestData('/login'),
    false => RequestData(
        _getDocFromHash_r,
        json: {
          'docPath': docPath,
        },
        returnsBinary: true,
      )
  };
  debugPrint("fssgfsfsdf" + rd.toString());

  parser(http.BaseResponse _res) async {
    final res = _res.forceRes();
    if (res == null || res.statusCode ~/ 100 != 2)
      return null;
    else {
      try {
        await API().local.storeDoc(res.bodyBytes, docPath.split('/').last);
        return API().local.readDoc(docPath.split('/').last);
      } catch (e) {
        debugPrint("failed to load webimg: " + e.toString());
      }
    }
  }

  return RequestAndParser(rd: rd, parser: parser);
}