requestFileHelperThread method

Future<RequestThreadFileHelperResult> requestFileHelperThread()

Implementation

Future<RequestThreadFileHelperResult> requestFileHelperThread() async {
  /// sp初始化
  await SpUtil.getInstance();
  //
  bool? isAuthenticated = SpUtil.getBool(BytedeskConstants.isAuthenticated);
  if (!isAuthenticated!) {
    return const RequestThreadFileHelperResult(
        statusCode: -1, message: "not authenticated");
  }
  //
  final threadUrl =
      BytedeskUtils.getHostUri('/api/thread/filehelper', {'client': client});
  BytedeskUtils.printLog(threadUrl);
  final initResponse = await httpClient.get(threadUrl, headers: getHeaders());

  //解决json解析中的乱码问题
  Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
  //将string类型数据 转换为json类型的数据
  final responseJson =
      json.decode(utf8decoder.convert(initResponse.bodyBytes));
  debugPrint("requestFileHelperThread: $responseJson");
  // 判断token是否过期
  if (responseJson.toString().contains('invalid_token')) {
    bytedeskEventBus.fire(InvalidTokenEventBus());
  }

  return RequestThreadFileHelperResult.fromJson(responseJson);
}