aboutsummaryrefslogtreecommitdiff
path: root/src/DownloadUtils.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-11-19 17:03:49 +0100
committerdec05eba <dec05eba@protonmail.com>2020-11-19 17:03:49 +0100
commitd5da6e47e14831b865d418faa32f32df4de5af42 (patch)
treecf14a47cba90642c50dbba6af0922c26c9cb266c /src/DownloadUtils.cpp
parent9134914f6065c0b248dd1b4317dbf9b16f5f52b5 (diff)
Matrix: fix too long path in event cache, bug when not using error handler..
Diffstat (limited to 'src/DownloadUtils.cpp')
-rw-r--r--src/DownloadUtils.cpp17
1 files changed, 12 insertions, 5 deletions
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<CommandArg> &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<CommandArg> &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) {