From d5da6e47e14831b865d418faa32f32df4de5af42 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Thu, 19 Nov 2020 17:03:49 +0100 Subject: Matrix: fix too long path in event cache, bug when not using error handler.. --- src/DownloadUtils.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/DownloadUtils.cpp') diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index 2a3f9d3..dae013d 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -52,9 +52,16 @@ namespace QuickMedia { return DownloadResult::OK; } - DownloadResult download_to_string_cache(const std::string &url, std::string &result, const std::vector &additional_args, bool use_tor, bool use_browser_useragent, DownloadErrorHandler error_handler) { - Path media_dir = get_cache_dir().join("media"); - Path media_file_path = Path(media_dir).join(base64_url::encode(url)); + DownloadResult download_to_string_cache(const std::string &url, std::string &result, const std::vector &additional_args, bool use_tor, bool use_browser_useragent, DownloadErrorHandler error_handler, Path cache_path) { + Path media_dir; + Path media_file_path; + if(cache_path.data.empty()) { + media_dir = get_cache_dir().join("media"); + media_file_path = Path(media_dir).join(base64_url::encode(url)); + } else { + media_dir = cache_path.parent(); + media_file_path = std::move(cache_path); + } if(get_file_type(media_file_path) == FileType::REGULAR) { if(file_get_content(media_file_path, result) == 0) { fprintf(stderr, "Loaded %s from cache\n", url.c_str()); @@ -65,8 +72,8 @@ namespace QuickMedia { } } else { DownloadResult download_result = download_to_string(url, result, additional_args, use_tor, use_browser_useragent, error_handler ? false : true); - if(!error_handler(result)) - download_result = DownloadResult::ERR; + if(error_handler) + download_result = error_handler(result) ? DownloadResult::OK : DownloadResult::ERR; if(download_result == DownloadResult::OK) { Path media_file_path_tmp(media_file_path.data + ".tmp"); if(create_directory_recursive(media_dir) == 0 && file_overwrite(media_file_path_tmp, result) == 0) { -- cgit v1.2.3