diff --git a/inbox.py b/inbox.py index 8224e0a77..3aaab8145 100644 --- a/inbox.py +++ b/inbox.py @@ -201,28 +201,29 @@ def cache_svg_images(session, base_dir: str, http_prefix: str, image_data = fp_svg.read() except OSError: print('EX: unable to read svg file data') - if image_data: - image_data = image_data.decode() - cleaned_up = \ - remove_script(image_data, log_filename, actor, url) - if cleaned_up != image_data: - # write the cleaned up svg image - svg_written = False - cleaned_up = cleaned_up.encode('utf-8') - try: - with open(image_filename, 'wb') as im_file: - im_file.write(cleaned_up) - svg_written = True - except OSError: - print('EX: unable to write cleaned up svg ' + url) - if svg_written: - # change the url to be the local version - obj['attachment'][index]['url'] = \ - http_prefix + '://' + domain_full + '/media/' + \ - post_id + '_' + filename - cached = True - else: + if not image_data: + continue + image_data = image_data.decode() + cleaned_up = \ + remove_script(image_data, log_filename, actor, url) + if cleaned_up != image_data: + # write the cleaned up svg image + svg_written = False + cleaned_up = cleaned_up.encode('utf-8') + try: + with open(image_filename, 'wb') as im_file: + im_file.write(cleaned_up) + svg_written = True + except OSError: + print('EX: unable to write cleaned up svg ' + url) + if svg_written: + # change the url to be the local version + obj['attachment'][index]['url'] = \ + http_prefix + '://' + domain_full + '/media/' + \ + post_id + '_' + filename cached = True + else: + cached = True return cached @@ -3081,29 +3082,30 @@ def _like_notify(base_dir: str, domain: str, print('_like_notify liker_handle: ' + str(liker_nickname) + '@' + str(liker_domain)) liker_handle = actor - if liker_handle != handle: - like_str = liker_handle + ' ' + url + '?likedBy=' + actor - prev_like_file = account_dir + '/.prevLike' - # was there a previous like notification? - if os.path.isfile(prev_like_file): - # is it the same as the current notification ? - with open(prev_like_file, 'r', encoding='utf-8') as fp_like: - prev_like_str = fp_like.read() - if prev_like_str == like_str: - return - try: - with open(prev_like_file, 'w+', encoding='utf-8') as fp_like: - fp_like.write(like_str) - except OSError: - print('EX: ERROR: unable to save previous like notification ' + - prev_like_file) + if liker_handle == handle: + return + like_str = liker_handle + ' ' + url + '?likedBy=' + actor + prev_like_file = account_dir + '/.prevLike' + # was there a previous like notification? + if os.path.isfile(prev_like_file): + # is it the same as the current notification ? + with open(prev_like_file, 'r', encoding='utf-8') as fp_like: + prev_like_str = fp_like.read() + if prev_like_str == like_str: + return + try: + with open(prev_like_file, 'w+', encoding='utf-8') as fp_like: + fp_like.write(like_str) + except OSError: + print('EX: ERROR: unable to save previous like notification ' + + prev_like_file) - try: - with open(like_file, 'w+', encoding='utf-8') as fp_like: - fp_like.write(like_str) - except OSError: - print('EX: ERROR: unable to write like notification file ' + - like_file) + try: + with open(like_file, 'w+', encoding='utf-8') as fp_like: + fp_like.write(like_str) + except OSError: + print('EX: ERROR: unable to write like notification file ' + + like_file) def _reaction_notify(base_dir: str, domain: str, onion_domain: str, @@ -3143,31 +3145,32 @@ def _reaction_notify(base_dir: str, domain: str, onion_domain: str, print('_reaction_notify reaction_handle: ' + str(reaction_nickname) + '@' + str(reaction_domain)) reaction_handle = actor - if reaction_handle != handle: - reaction_str = \ - reaction_handle + ' ' + url + '?reactBy=' + actor + \ - ';emoj=' + emoji_content - prev_reaction_file = account_dir + '/.prevReaction' - # was there a previous reaction notification? - if os.path.isfile(prev_reaction_file): - # is it the same as the current notification ? - with open(prev_reaction_file, 'r', encoding='utf-8') as fp_react: - prev_reaction_str = fp_react.read() - if prev_reaction_str == reaction_str: - return - try: - with open(prev_reaction_file, 'w+', encoding='utf-8') as fp_react: - fp_react.write(reaction_str) - except OSError: - print('EX: ERROR: unable to save previous reaction notification ' + - prev_reaction_file) + if reaction_handle == handle: + return + reaction_str = \ + reaction_handle + ' ' + url + '?reactBy=' + actor + \ + ';emoj=' + emoji_content + prev_reaction_file = account_dir + '/.prevReaction' + # was there a previous reaction notification? + if os.path.isfile(prev_reaction_file): + # is it the same as the current notification ? + with open(prev_reaction_file, 'r', encoding='utf-8') as fp_react: + prev_reaction_str = fp_react.read() + if prev_reaction_str == reaction_str: + return + try: + with open(prev_reaction_file, 'w+', encoding='utf-8') as fp_react: + fp_react.write(reaction_str) + except OSError: + print('EX: ERROR: unable to save previous reaction notification ' + + prev_reaction_file) - try: - with open(reaction_file, 'w+', encoding='utf-8') as fp_react: - fp_react.write(reaction_str) - except OSError: - print('EX: ERROR: unable to write reaction notification file ' + - reaction_file) + try: + with open(reaction_file, 'w+', encoding='utf-8') as fp_react: + fp_react.write(reaction_str) + except OSError: + print('EX: ERROR: unable to write reaction notification file ' + + reaction_file) def _notify_post_arrival(base_dir: str, handle: str, url: str) -> None: diff --git a/utils.py b/utils.py index bdb40204a..ab115919b 100644 --- a/utils.py +++ b/utils.py @@ -496,7 +496,7 @@ def get_audio_extensions() -> []: def get_image_extensions() -> []: """Returns a list of the possible image file extensions """ - return ('png', 'jpg', 'jpeg', 'gif', 'webp', 'avif', 'svg', 'ico', 'jxl') + return ('jpg', 'jpeg', 'gif', 'webp', 'avif', 'svg', 'ico', 'jxl', 'png') def get_image_mime_type(image_filename: str) -> str: diff --git a/webapp_profile.py b/webapp_profile.py index f8b084284..b7129b0f6 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -68,7 +68,7 @@ from webapp_utils import html_header_with_external_style from webapp_utils import html_header_with_person_markup from webapp_utils import html_footer from webapp_utils import add_emoji_to_display_name -from webapp_utils import get_banner_file +from webapp_utils import get_profile_background_file from webapp_utils import html_post_separator from webapp_utils import edit_check_box from webapp_utils import edit_text_field @@ -404,8 +404,8 @@ def html_profile_after_search(recent_posts_cache: {}, max_recent_posts: int, profile_str + html_footer() -def _get_profile_header(http_prefix: str, nickname: str, - domain_full: str, translate: {}, +def _get_profile_header(base_dir: str, http_prefix: str, nickname: str, + domain: str, domain_full: str, translate: {}, default_timeline: str, display_name: str, profile_description_short: str, @@ -419,6 +419,8 @@ def _get_profile_header(http_prefix: str, nickname: str, """The header of the profile screen, containing background image and avatar """ + banner_file, _ = \ + get_profile_background_file(base_dir, nickname, domain, theme) html_str = \ '\n\n
\n' + \ ' \n' + \ ' \n' + \ + 'src="/users/' + nickname + '/' + banner_file + '" />\n' + \ '
\n' + \ ' (str, str):