mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
5b7ea48e4a
137
inbox.py
137
inbox.py
|
@ -201,28 +201,29 @@ def cache_svg_images(session, base_dir: str, http_prefix: str,
|
||||||
image_data = fp_svg.read()
|
image_data = fp_svg.read()
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to read svg file data')
|
print('EX: unable to read svg file data')
|
||||||
if image_data:
|
if not image_data:
|
||||||
image_data = image_data.decode()
|
continue
|
||||||
cleaned_up = \
|
image_data = image_data.decode()
|
||||||
remove_script(image_data, log_filename, actor, url)
|
cleaned_up = \
|
||||||
if cleaned_up != image_data:
|
remove_script(image_data, log_filename, actor, url)
|
||||||
# write the cleaned up svg image
|
if cleaned_up != image_data:
|
||||||
svg_written = False
|
# write the cleaned up svg image
|
||||||
cleaned_up = cleaned_up.encode('utf-8')
|
svg_written = False
|
||||||
try:
|
cleaned_up = cleaned_up.encode('utf-8')
|
||||||
with open(image_filename, 'wb') as im_file:
|
try:
|
||||||
im_file.write(cleaned_up)
|
with open(image_filename, 'wb') as im_file:
|
||||||
svg_written = True
|
im_file.write(cleaned_up)
|
||||||
except OSError:
|
svg_written = True
|
||||||
print('EX: unable to write cleaned up svg ' + url)
|
except OSError:
|
||||||
if svg_written:
|
print('EX: unable to write cleaned up svg ' + url)
|
||||||
# change the url to be the local version
|
if svg_written:
|
||||||
obj['attachment'][index]['url'] = \
|
# change the url to be the local version
|
||||||
http_prefix + '://' + domain_full + '/media/' + \
|
obj['attachment'][index]['url'] = \
|
||||||
post_id + '_' + filename
|
http_prefix + '://' + domain_full + '/media/' + \
|
||||||
cached = True
|
post_id + '_' + filename
|
||||||
else:
|
|
||||||
cached = True
|
cached = True
|
||||||
|
else:
|
||||||
|
cached = True
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
|
|
||||||
|
@ -3081,29 +3082,30 @@ def _like_notify(base_dir: str, domain: str,
|
||||||
print('_like_notify liker_handle: ' +
|
print('_like_notify liker_handle: ' +
|
||||||
str(liker_nickname) + '@' + str(liker_domain))
|
str(liker_nickname) + '@' + str(liker_domain))
|
||||||
liker_handle = actor
|
liker_handle = actor
|
||||||
if liker_handle != handle:
|
if liker_handle == handle:
|
||||||
like_str = liker_handle + ' ' + url + '?likedBy=' + actor
|
return
|
||||||
prev_like_file = account_dir + '/.prevLike'
|
like_str = liker_handle + ' ' + url + '?likedBy=' + actor
|
||||||
# was there a previous like notification?
|
prev_like_file = account_dir + '/.prevLike'
|
||||||
if os.path.isfile(prev_like_file):
|
# was there a previous like notification?
|
||||||
# is it the same as the current notification ?
|
if os.path.isfile(prev_like_file):
|
||||||
with open(prev_like_file, 'r', encoding='utf-8') as fp_like:
|
# is it the same as the current notification ?
|
||||||
prev_like_str = fp_like.read()
|
with open(prev_like_file, 'r', encoding='utf-8') as fp_like:
|
||||||
if prev_like_str == like_str:
|
prev_like_str = fp_like.read()
|
||||||
return
|
if prev_like_str == like_str:
|
||||||
try:
|
return
|
||||||
with open(prev_like_file, 'w+', encoding='utf-8') as fp_like:
|
try:
|
||||||
fp_like.write(like_str)
|
with open(prev_like_file, 'w+', encoding='utf-8') as fp_like:
|
||||||
except OSError:
|
fp_like.write(like_str)
|
||||||
print('EX: ERROR: unable to save previous like notification ' +
|
except OSError:
|
||||||
prev_like_file)
|
print('EX: ERROR: unable to save previous like notification ' +
|
||||||
|
prev_like_file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(like_file, 'w+', encoding='utf-8') as fp_like:
|
with open(like_file, 'w+', encoding='utf-8') as fp_like:
|
||||||
fp_like.write(like_str)
|
fp_like.write(like_str)
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: ERROR: unable to write like notification file ' +
|
print('EX: ERROR: unable to write like notification file ' +
|
||||||
like_file)
|
like_file)
|
||||||
|
|
||||||
|
|
||||||
def _reaction_notify(base_dir: str, domain: str, onion_domain: str,
|
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: ' +
|
print('_reaction_notify reaction_handle: ' +
|
||||||
str(reaction_nickname) + '@' + str(reaction_domain))
|
str(reaction_nickname) + '@' + str(reaction_domain))
|
||||||
reaction_handle = actor
|
reaction_handle = actor
|
||||||
if reaction_handle != handle:
|
if reaction_handle == handle:
|
||||||
reaction_str = \
|
return
|
||||||
reaction_handle + ' ' + url + '?reactBy=' + actor + \
|
reaction_str = \
|
||||||
';emoj=' + emoji_content
|
reaction_handle + ' ' + url + '?reactBy=' + actor + \
|
||||||
prev_reaction_file = account_dir + '/.prevReaction'
|
';emoj=' + emoji_content
|
||||||
# was there a previous reaction notification?
|
prev_reaction_file = account_dir + '/.prevReaction'
|
||||||
if os.path.isfile(prev_reaction_file):
|
# was there a previous reaction notification?
|
||||||
# is it the same as the current notification ?
|
if os.path.isfile(prev_reaction_file):
|
||||||
with open(prev_reaction_file, 'r', encoding='utf-8') as fp_react:
|
# is it the same as the current notification ?
|
||||||
prev_reaction_str = fp_react.read()
|
with open(prev_reaction_file, 'r', encoding='utf-8') as fp_react:
|
||||||
if prev_reaction_str == reaction_str:
|
prev_reaction_str = fp_react.read()
|
||||||
return
|
if prev_reaction_str == reaction_str:
|
||||||
try:
|
return
|
||||||
with open(prev_reaction_file, 'w+', encoding='utf-8') as fp_react:
|
try:
|
||||||
fp_react.write(reaction_str)
|
with open(prev_reaction_file, 'w+', encoding='utf-8') as fp_react:
|
||||||
except OSError:
|
fp_react.write(reaction_str)
|
||||||
print('EX: ERROR: unable to save previous reaction notification ' +
|
except OSError:
|
||||||
prev_reaction_file)
|
print('EX: ERROR: unable to save previous reaction notification ' +
|
||||||
|
prev_reaction_file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(reaction_file, 'w+', encoding='utf-8') as fp_react:
|
with open(reaction_file, 'w+', encoding='utf-8') as fp_react:
|
||||||
fp_react.write(reaction_str)
|
fp_react.write(reaction_str)
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: ERROR: unable to write reaction notification file ' +
|
print('EX: ERROR: unable to write reaction notification file ' +
|
||||||
reaction_file)
|
reaction_file)
|
||||||
|
|
||||||
|
|
||||||
def _notify_post_arrival(base_dir: str, handle: str, url: str) -> None:
|
def _notify_post_arrival(base_dir: str, handle: str, url: str) -> None:
|
||||||
|
|
2
utils.py
2
utils.py
|
@ -496,7 +496,7 @@ def get_audio_extensions() -> []:
|
||||||
def get_image_extensions() -> []:
|
def get_image_extensions() -> []:
|
||||||
"""Returns a list of the possible image file 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:
|
def get_image_mime_type(image_filename: str) -> str:
|
||||||
|
|
|
@ -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_header_with_person_markup
|
||||||
from webapp_utils import html_footer
|
from webapp_utils import html_footer
|
||||||
from webapp_utils import add_emoji_to_display_name
|
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 html_post_separator
|
||||||
from webapp_utils import edit_check_box
|
from webapp_utils import edit_check_box
|
||||||
from webapp_utils import edit_text_field
|
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()
|
profile_str + html_footer()
|
||||||
|
|
||||||
|
|
||||||
def _get_profile_header(http_prefix: str, nickname: str,
|
def _get_profile_header(base_dir: str, http_prefix: str, nickname: str,
|
||||||
domain_full: str, translate: {},
|
domain: str, domain_full: str, translate: {},
|
||||||
default_timeline: str,
|
default_timeline: str,
|
||||||
display_name: str,
|
display_name: str,
|
||||||
profile_description_short: 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
|
"""The header of the profile screen, containing background
|
||||||
image and avatar
|
image and avatar
|
||||||
"""
|
"""
|
||||||
|
banner_file, _ = \
|
||||||
|
get_profile_background_file(base_dir, nickname, domain, theme)
|
||||||
html_str = \
|
html_str = \
|
||||||
'\n\n <figure class="profileHeader">\n' + \
|
'\n\n <figure class="profileHeader">\n' + \
|
||||||
' <a href="/users/' + \
|
' <a href="/users/' + \
|
||||||
|
@ -427,7 +429,7 @@ def _get_profile_header(http_prefix: str, nickname: str,
|
||||||
'accesskey="' + access_keys['menuTimeline'] + '">\n' + \
|
'accesskey="' + access_keys['menuTimeline'] + '">\n' + \
|
||||||
' <img class="profileBackground" ' + \
|
' <img class="profileBackground" ' + \
|
||||||
'alt="" ' + \
|
'alt="" ' + \
|
||||||
'src="/users/' + nickname + '/image_' + theme + '.png" /></a>\n' + \
|
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
|
||||||
' <figcaption>\n' + \
|
' <figcaption>\n' + \
|
||||||
' <a href="/users/' + \
|
' <a href="/users/' + \
|
||||||
nickname + '/' + default_timeline + '" title="' + \
|
nickname + '/' + default_timeline + '" title="' + \
|
||||||
|
@ -904,9 +906,9 @@ def html_profile(signing_priv_key_pem: str,
|
||||||
pinned_content = pin_file.read()
|
pinned_content = pin_file.read()
|
||||||
|
|
||||||
profile_header_str = \
|
profile_header_str = \
|
||||||
_get_profile_header(http_prefix,
|
_get_profile_header(base_dir, http_prefix,
|
||||||
nickname,
|
nickname,
|
||||||
domain_full, translate,
|
domain, domain_full, translate,
|
||||||
default_timeline, display_name,
|
default_timeline, display_name,
|
||||||
profile_description_short,
|
profile_description_short,
|
||||||
login_button, avatar_url, theme,
|
login_button, avatar_url, theme,
|
||||||
|
@ -2302,7 +2304,7 @@ def html_edit_profile(server, translate: {},
|
||||||
|
|
||||||
# filename of the banner shown at the top
|
# filename of the banner shown at the top
|
||||||
banner_file, _ = \
|
banner_file, _ = \
|
||||||
get_banner_file(base_dir, nickname, domain, theme)
|
get_profile_background_file(base_dir, nickname, domain, theme)
|
||||||
|
|
||||||
display_nickname = nickname
|
display_nickname = nickname
|
||||||
is_bot = is_group = follow_dms = remove_twitter = ''
|
is_bot = is_group = follow_dms = remove_twitter = ''
|
||||||
|
|
|
@ -547,11 +547,12 @@ def _get_image_file(base_dir: str, name: str, directory: str,
|
||||||
banner_extensions = get_image_extensions()
|
banner_extensions = get_image_extensions()
|
||||||
banner_file = ''
|
banner_file = ''
|
||||||
banner_filename = ''
|
banner_filename = ''
|
||||||
|
im_name = name
|
||||||
for ext in banner_extensions:
|
for ext in banner_extensions:
|
||||||
banner_file_test = name + '.' + ext
|
banner_file_test = im_name + '.' + ext
|
||||||
banner_filename_test = directory + '/' + banner_file_test
|
banner_filename_test = directory + '/' + banner_file_test
|
||||||
if os.path.isfile(banner_filename_test):
|
if os.path.isfile(banner_filename_test):
|
||||||
banner_file = name + '_' + theme + '.' + ext
|
banner_file = banner_file_test
|
||||||
banner_filename = banner_filename_test
|
banner_filename = banner_filename_test
|
||||||
return banner_file, banner_filename
|
return banner_file, banner_filename
|
||||||
# if not found then use the default image
|
# 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)
|
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,
|
def get_search_banner_file(base_dir: str,
|
||||||
nickname: str, domain: str,
|
nickname: str, domain: str,
|
||||||
theme: str) -> (str, str):
|
theme: str) -> (str, str):
|
||||||
|
|
Loading…
Reference in New Issue