refreshThread method

Future<Uint8List> refreshThread(
  1. String server,
  2. String shortlink
)

Implementation

Future<Uint8List> refreshThread(String server, String shortlink) async {
  if (!_handshaked && _katamari.isEmpty) return handshake(server, _katamari);

  uri = server;

  var url = Uri.parse(uri + '/t/' + shortlink + '?bin=true');
  //var response =
  //    await http.post(url, body: {'name': 'doodle', 'color': 'blue'});

  var response;
  try {
    response = await http.post(url, body: {
      'katamari': base64Encode(_katamari)
    }, headers: {
      'Cookie': 'DARTSESSID=' + dartSessionId
    }).timeout(_timoutIn);
  } catch (e) {
    if (!(e is TimeoutException)) setOffline();
    return Uint8List(0);
  }

  //var response =
  //    await http.get(url, headers: {'Cookie': 'DARTSESSID=' + dartSessionId});
  if (response == null) return Uint8List(0);
  setOnline();
  if (response.statusCode != 200) return Uint8List(0);
  print('Response status: ${response.statusCode}');
  String? h = response.headers["set-cookie"];
  if (h != null) {
    cookie = h.split(' ').first;
    String dSid = cookie.split('=').last;
    dartSessionId = dSid.substring(0, dSid.length - 1);
  }
  print(cookie);
  print(response.contentLength);
  String? hw = response.headers["xxwants"];
  if (hw != null) {
    xxWantsList = base64Decode(hw);
  } else {
    //empty list
    xxWantsList = Uint8List(0);
  }
  return response.bodyBytes;
}