From 221522cf995cbcd39c956f66423a26bbccae8f72 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 16 Oct 2020 04:49:14 +0200 Subject: Matrix: stream download to rapidjson parser --- src/plugins/Matrix.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 3637d41..a0d8568 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -1730,22 +1730,12 @@ namespace QuickMedia { } DownloadResult Matrix::download_json(rapidjson::Document &result, const std::string &url, std::vector additional_args, bool use_browser_useragent, std::string *err_msg) const { - std::string server_response; - if(download_to_string(url, server_response, std::move(additional_args), use_tor, use_browser_useragent, err_msg == nullptr) != DownloadResult::OK) { + if(download_to_json(url, result, std::move(additional_args), use_tor, use_browser_useragent, err_msg == nullptr) != DownloadResult::OK) { + // Cant get error since we parse directory to json. TODO: Make this work somehow? if(err_msg) - *err_msg = server_response; + *err_msg = "Failed to download/parse json"; return DownloadResult::NET_ERR; } - - rapidjson::ParseResult parse_result = result.Parse(server_response.c_str(), server_response.size()); - if(parse_result.IsError()) { - std::string error_code_str = std::to_string(parse_result.Code()); - fprintf(stderr, "download_json error: %s\n", error_code_str.c_str()); - if(err_msg) - *err_msg = "Json parse error: " + std::move(error_code_str); - return DownloadResult::ERR; - } - return DownloadResult::OK; } } \ No newline at end of file -- cgit v1.2.3