newThread method
Implementation
Future<Uint8List> newThread(
String _baseUri,
String text,
String preEntry,
Uint8List katamari,
String nick,
String avatar,
Uint8List attachment) async {
var url = Uri.parse(_baseUri + '/new/' + preEntry + '?bin=true');
print('newThread:' + text);
var response;
try {
response = await http.post(url, body: {
'post': text,
'katamari': base64Encode(katamari),
'nick': nick,
'avatar': avatar,
'attachment': base64Encode(attachment)
}, headers: {
'Cookie': 'DARTSESSID=' + dartSessionId
}).timeout(_timoutIn);
} catch (e) {
if (!(e is TimeoutException)) setOffline();
return Uint8List(0);
}
if (response == null) return Uint8List(0);
setOnline();
if (response.statusCode == 409) {
//dup
return Uint8List(1);
}
if (response.statusCode == 502) {
//dup
return Uint8List(2);
}
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);
return response.bodyBytes;
}