From ced75a7b3d9aebbce7d2dfed815b535604b74d24 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 19 Aug 2022 17:00:33 +0100 Subject: [PATCH 1/6] Less indentation --- inbox.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/inbox.py b/inbox.py index 8224e0a77..91a06acc1 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 From f2917482db75aaa33be76f68080f4c0339a3d247 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 19 Aug 2022 17:22:53 +0100 Subject: [PATCH 2/6] Less indentation --- inbox.py | 94 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/inbox.py b/inbox.py index 91a06acc1..3aaab8145 100644 --- a/inbox.py +++ b/inbox.py @@ -3082,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, @@ -3144,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: From bc8f0802992e52ce5d983d5be88f17cae1ef97ee Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 20 Aug 2022 14:01:12 +0100 Subject: [PATCH 3/6] Change sequence of image extensions --- utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 0abfb4fafc57dff197ffa26044d2215131b901f7 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 20 Aug 2022 14:18:26 +0100 Subject: [PATCH 4/6] Set profile background image --- webapp_profile.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/webapp_profile.py b/webapp_profile.py index f8b084284..019fefe7e 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -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_banner_file(base_dir, nickname, domain, theme) html_str = \ '\n\n
\n' + \ ' \n' + \ ' \n' + \ + 'src="/users/' + nickname + '/' + banner_file + '" />\n' + \ '
\n' + \ ' \n' + \ ' (str, str):