diff --git a/cache.py b/cache.py index ab6fb19d0..bc8c7ab90 100644 --- a/cache.py +++ b/cache.py @@ -28,6 +28,7 @@ from utils import get_file_case_insensitive from utils import get_user_paths from utils import date_utcnow from utils import date_from_string_format +from utils import get_image_extensions from content import remove_script @@ -391,3 +392,21 @@ def update_recent_posts_cache(recent_posts_cache: {}, max_recent_posts: int, recent_posts_cache['html'] = {} recent_posts_cache['json'][post_id] = json.dumps(post_json_object) recent_posts_cache['html'][post_id] = html_str + + +def remove_avatar_from_cache(base_dir: str, actor_str: str) -> None: + """Removes any existing avatar entries from the cache + This avoids duplicate entries with differing extensions + """ + avatar_filename_extensions = get_image_extensions() + for extension in avatar_filename_extensions: + avatar_filename = \ + base_dir + '/cache/avatars/' + actor_str + '.' + extension + if not os.path.isfile(avatar_filename): + continue + try: + os.remove(avatar_filename) + except OSError: + print('EX: remove_avatar_from_cache ' + + 'unable to delete cached avatar ' + + str(avatar_filename)) diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 9aa4686b8..9dc371ce0 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -22,7 +22,6 @@ from flags import is_memorial_account from flags import is_premium_account from utils import data_dir from utils import set_premium_account -from utils import remove_avatar_from_cache from utils import save_json from utils import save_reverse_timeline from utils import set_minimize_all_images @@ -141,6 +140,7 @@ from shares import merge_shared_item_tokens from roles import set_roles_from_list from schedule import remove_scheduled_posts from cwlists import get_cw_list_variable +from cache import remove_avatar_from_cache from cache import store_person_in_cache from daemon_utils import post_to_outbox diff --git a/inbox_receive.py b/inbox_receive.py index 7ab0fe945..4a733f062 100644 --- a/inbox_receive.py +++ b/inbox_receive.py @@ -41,7 +41,6 @@ from utils import get_actor_from_post from utils import locate_post from utils import remove_id_ending from utils import has_actor -from utils import remove_avatar_from_cache from utils import text_in_file from utils import is_account_dir from utils import data_dir @@ -53,6 +52,7 @@ from utils import get_url_from_post from utils import remove_html from utils import get_full_domain from utils import get_user_paths +from cache import remove_avatar_from_cache from cache import get_person_from_cache from cache import get_actor_public_key_from_id from cache import store_person_in_cache diff --git a/utils.py b/utils.py index aacfb451a..d0905aa6d 100644 --- a/utils.py +++ b/utils.py @@ -1066,24 +1066,6 @@ def get_link_prefixes() -> []: 'hyper://', 'gemini://', 'gopher://', 'briar:') -def remove_avatar_from_cache(base_dir: str, actor_str: str) -> None: - """Removes any existing avatar entries from the cache - This avoids duplicate entries with differing extensions - """ - avatar_filename_extensions = get_image_extensions() - for extension in avatar_filename_extensions: - avatar_filename = \ - base_dir + '/cache/avatars/' + actor_str + '.' + extension - if not os.path.isfile(avatar_filename): - continue - try: - os.remove(avatar_filename) - except OSError: - print('EX: remove_avatar_from_cache ' + - 'unable to delete cached avatar ' + - str(avatar_filename)) - - def save_json(json_object: {}, filename: str) -> bool: """Saves json to a file """