diff options
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | src/DownloadUtils.cpp | 23 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 3 |
3 files changed, 15 insertions, 17 deletions
@@ -134,4 +134,8 @@ Readd copying of Text in Body copy constructor. Find out why we need to make the Body items that are no longer visible should stop their thumbnail download/creation (moving to bottom of file-manager is very slow). Fix body flickering when moving up and there is a new local image to load. It happens because we have no idea how large the thumbnail is before loading it. Make body width the same as the window width (for the main body when there isn't a room list beside it) and pass margin to body draw. This is needed to allow swiping body from the window (screen) edge. -Restrict sf::View viewport in Body to x axis as well, to hide the body in the end when swiping right.
\ No newline at end of file +Restrict sf::View viewport in Body to x axis as well, to hide the body in the end when swiping right. +Ctrl+F to either bring up search that searches in the body (filtering, of searching for all messages in the room in matrix) or does an autocomplete search. For youtube that would be a google autocomplete search. + The autocomplete search menu should overlay the window (with translucent black overlay) and with the search bar in the middle and autocomplete results below. + Or do not have such an overlay and instead just put the autocomplete list below the search bar and close the autocomplete when pressing ESC or clicking inside the body or moving to another tab. +Automatically delete old thumbnails and media files.
\ No newline at end of file diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp index eb8fa63..9834390 100644 --- a/src/DownloadUtils.cpp +++ b/src/DownloadUtils.cpp @@ -2,7 +2,7 @@ #include "../include/Program.hpp" #include "../include/Storage.hpp" #include "../include/NetUtils.hpp" -#include "../external/cppcodec/base64_url.hpp" +#include "../external/hash-library/sha256.h" #include <unistd.h> #include <limits.h> #include <SFML/System/Clock.hpp> @@ -162,15 +162,15 @@ namespace QuickMedia { } DownloadResult download_to_string_cache(const std::string &url, std::string &result, const std::vector<CommandArg> &additional_args, 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(cppcodec::base64_url::encode(url)); + SHA256 sha256; + sha256.add(url.data(), url.size()); + media_file_path = get_cache_dir().join("media").join(sha256.getHash()); } 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()); @@ -183,17 +183,8 @@ namespace QuickMedia { DownloadResult download_result = download_to_string(url, result, additional_args, use_browser_useragent, error_handler ? false : true); if(download_result == DownloadResult::OK && 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) { - if(rename_atomic(media_file_path_tmp.data.c_str(), media_file_path.data.c_str()) != 0) { - perror("rename"); - download_result = DownloadResult::ERR; - } - } else { - download_result = DownloadResult::ERR; - } - } + if(download_result == DownloadResult::OK) + download_result = file_overwrite_atomic(media_file_path, result) == 0 ? DownloadResult::OK : DownloadResult::ERR; return download_result; } } diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 43ccbaf..a61b836 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -659,6 +659,9 @@ namespace QuickMedia { */ fprintf(stderr, "Monitor hz: %d\n", monitor_hz); + if(create_directory_recursive(get_cache_dir().join("media")) != 0) + throw std::runtime_error("Failed to create media directory"); + if(create_directory_recursive(get_cache_dir().join("thumbnails")) != 0) throw std::runtime_error("Failed to create thumbnails directory"); |