Merge branch 'main' of gitlab.com:bashrc2/epicyon

merge-requests/30/head
Bob Mottram 2022-08-20 15:00:17 +01:00
commit 5b7ea48e4a
4 changed files with 92 additions and 77 deletions

137
inbox.py
View File

@ -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:

View File

@ -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:

View File

@ -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 <figure class="profileHeader">\n' + \
' <a href="/users/' + \
@ -427,7 +429,7 @@ def _get_profile_header(http_prefix: str, nickname: str,
'accesskey="' + access_keys['menuTimeline'] + '">\n' + \
' <img class="profileBackground" ' + \
'alt="" ' + \
'src="/users/' + nickname + '/image_' + theme + '.png" /></a>\n' + \
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
' <figcaption>\n' + \
' <a href="/users/' + \
nickname + '/' + default_timeline + '" title="' + \
@ -904,9 +906,9 @@ def html_profile(signing_priv_key_pem: str,
pinned_content = pin_file.read()
profile_header_str = \
_get_profile_header(http_prefix,
_get_profile_header(base_dir, http_prefix,
nickname,
domain_full, translate,
domain, domain_full, translate,
default_timeline, display_name,
profile_description_short,
login_button, avatar_url, theme,
@ -2302,7 +2304,7 @@ def html_edit_profile(server, translate: {},
# filename of the banner shown at the top
banner_file, _ = \
get_banner_file(base_dir, nickname, domain, theme)
get_profile_background_file(base_dir, nickname, domain, theme)
display_nickname = nickname
is_bot = is_group = follow_dms = remove_twitter = ''

View File

@ -547,11 +547,12 @@ def _get_image_file(base_dir: str, name: str, directory: str,
banner_extensions = get_image_extensions()
banner_file = ''
banner_filename = ''
im_name = name
for ext in banner_extensions:
banner_file_test = name + '.' + ext
banner_file_test = im_name + '.' + ext
banner_filename_test = directory + '/' + banner_file_test
if os.path.isfile(banner_filename_test):
banner_file = name + '_' + theme + '.' + ext
banner_file = banner_file_test
banner_filename = banner_filename_test
return banner_file, banner_filename
# if not found then use the default image
@ -575,6 +576,15 @@ def get_banner_file(base_dir: str,
return _get_image_file(base_dir, 'banner', account_dir, theme)
def get_profile_background_file(base_dir: str,
nickname: str, domain: str,
theme: str) -> (str, str):
"""Gets the image for the profile background
"""
account_dir = acct_dir(base_dir, nickname, domain)
return _get_image_file(base_dir, 'image', account_dir, theme)
def get_search_banner_file(base_dir: str,
nickname: str, domain: str,
theme: str) -> (str, str):