mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
6ad7eaa446
64
content.py
64
content.py
|
@ -15,6 +15,7 @@ import email.parser
|
|||
import urllib.parse
|
||||
from shutil import copyfile
|
||||
from dateutil.parser import parse
|
||||
from utils import get_user_paths
|
||||
from utils import convert_published_to_local_timezone
|
||||
from utils import has_object_dict
|
||||
from utils import valid_hash_tag
|
||||
|
@ -742,8 +743,28 @@ def post_tag_exists(tagType: str, tagName: str, tags: {}) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _add_mention(word_str: str, http_prefix: str, following: str,
|
||||
petnames: str, replace_mentions: {},
|
||||
def _mention_to_url(base_dir: str, http_prefix: str,
|
||||
domain: str, nickname: str) -> str:
|
||||
"""Convert https://somedomain/@somenick to
|
||||
https://somedomain/users/somenick
|
||||
This uses the hack of trying the cache directory to see if
|
||||
there is a matching actor
|
||||
"""
|
||||
possible_paths = get_user_paths()
|
||||
cache_dir = base_dir + '/cache/actors'
|
||||
cache_path_start = cache_dir + '/' + http_prefix + ':##' + domain
|
||||
for users_path in possible_paths:
|
||||
users_path = users_path.replace('/', '#')
|
||||
possible_cache_entry = \
|
||||
cache_path_start + users_path + nickname + '.json'
|
||||
if os.path.isfile(possible_cache_entry):
|
||||
return http_prefix + '://' + \
|
||||
domain + users_path.replace('#', '/') + nickname
|
||||
return http_prefix + '://' + domain + '/users/' + nickname
|
||||
|
||||
|
||||
def _add_mention(base_dir: str, word_str: str, http_prefix: str,
|
||||
following: [], petnames: [], replace_mentions: {},
|
||||
recipients: [], tags: {}) -> bool:
|
||||
"""Detects mentions and adds them to the replacements dict and
|
||||
recipients list
|
||||
|
@ -761,8 +782,9 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
if possible_nickname == follow_nick:
|
||||
follow_str = remove_eol(follow)
|
||||
replace_domain = follow_str.split('@')[1]
|
||||
recipient_actor = http_prefix + "://" + \
|
||||
replace_domain + "/@" + possible_nickname
|
||||
recipient_actor = \
|
||||
_mention_to_url(base_dir, http_prefix,
|
||||
replace_domain, possible_nickname)
|
||||
if recipient_actor not in recipients:
|
||||
recipients.append(recipient_actor)
|
||||
tags[word_str] = {
|
||||
|
@ -771,8 +793,7 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
'type': 'Mention'
|
||||
}
|
||||
replace_mentions[word_str] = \
|
||||
"<span class=\"h-card\"><a href=\"" + http_prefix + \
|
||||
"://" + replace_domain + "/@" + possible_nickname + \
|
||||
"<span class=\"h-card\"><a href=\"" + recipient_actor + \
|
||||
"\" tabindex=\"10\" class=\"u-url mention\">@<span>" + \
|
||||
possible_nickname + "</span></a></span>"
|
||||
return True
|
||||
|
@ -788,8 +809,9 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
follow_str = remove_eol(follow)
|
||||
replace_nickname = follow_str.split('@')[0]
|
||||
replace_domain = follow_str.split('@')[1]
|
||||
recipient_actor = http_prefix + "://" + \
|
||||
replace_domain + "/@" + replace_nickname
|
||||
recipient_actor = \
|
||||
_mention_to_url(base_dir, http_prefix,
|
||||
replace_domain, replace_nickname)
|
||||
if recipient_actor not in recipients:
|
||||
recipients.append(recipient_actor)
|
||||
tags[word_str] = {
|
||||
|
@ -798,9 +820,8 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
'type': 'Mention'
|
||||
}
|
||||
replace_mentions[word_str] = \
|
||||
"<span class=\"h-card\"><a href=\"" + http_prefix + \
|
||||
"://" + replace_domain + "/@" + replace_nickname + \
|
||||
"\" tabindex=\"10\" " + \
|
||||
"<span class=\"h-card\"><a href=\"" + \
|
||||
recipient_actor + "\" tabindex=\"10\" " + \
|
||||
"class=\"u-url mention\">@<span>" + \
|
||||
replace_nickname + "</span></a></span>"
|
||||
return True
|
||||
|
@ -821,8 +842,9 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
for follow in following:
|
||||
if remove_eol(follow) != possible_handle:
|
||||
continue
|
||||
recipient_actor = http_prefix + "://" + \
|
||||
possible_domain + "/@" + possible_nickname
|
||||
recipient_actor = \
|
||||
_mention_to_url(base_dir, http_prefix,
|
||||
possible_domain, possible_nickname)
|
||||
if recipient_actor not in recipients:
|
||||
recipients.append(recipient_actor)
|
||||
tags[word_str] = {
|
||||
|
@ -831,16 +853,16 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
'type': 'Mention'
|
||||
}
|
||||
replace_mentions[word_str] = \
|
||||
"<span class=\"h-card\"><a href=\"" + http_prefix + \
|
||||
"://" + possible_domain + "/@" + possible_nickname + \
|
||||
"<span class=\"h-card\"><a href=\"" + recipient_actor + \
|
||||
"\" tabindex=\"10\" class=\"u-url mention\">@<span>" + \
|
||||
possible_nickname + "</span></a></span>"
|
||||
return True
|
||||
# @nick@domain
|
||||
if not (possible_domain == 'localhost' or '.' in possible_domain):
|
||||
return False
|
||||
recipient_actor = http_prefix + "://" + \
|
||||
possible_domain + "/@" + possible_nickname
|
||||
recipient_actor = \
|
||||
_mention_to_url(base_dir, http_prefix,
|
||||
possible_domain, possible_nickname)
|
||||
if recipient_actor not in recipients:
|
||||
recipients.append(recipient_actor)
|
||||
tags[word_str] = {
|
||||
|
@ -849,8 +871,7 @@ def _add_mention(word_str: str, http_prefix: str, following: str,
|
|||
'type': 'Mention'
|
||||
}
|
||||
replace_mentions[word_str] = \
|
||||
"<span class=\"h-card\"><a href=\"" + http_prefix + \
|
||||
"://" + possible_domain + "/@" + possible_nickname + \
|
||||
"<span class=\"h-card\"><a href=\"" + recipient_actor + \
|
||||
"\" tabindex=\"10\" class=\"u-url mention\">@<span>" + \
|
||||
possible_nickname + "</span></a></span>"
|
||||
return True
|
||||
|
@ -1225,8 +1246,9 @@ def add_html_tags(base_dir: str, http_prefix: str,
|
|||
long_words_list.append(word_str)
|
||||
first_char = word_str[0]
|
||||
if first_char == '@':
|
||||
if _add_mention(word_str, http_prefix, following, petnames,
|
||||
replace_mentions, recipients, hashtags):
|
||||
if _add_mention(base_dir, word_str, http_prefix, following,
|
||||
petnames, replace_mentions, recipients,
|
||||
hashtags):
|
||||
prev_word_str = ''
|
||||
continue
|
||||
elif first_char == '#':
|
||||
|
|
28
daemon.py
28
daemon.py
|
@ -3995,13 +3995,16 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
break
|
||||
# skill search
|
||||
search_str = search_str.replace('*', '').strip()
|
||||
nickname = get_nickname_from_actor(actor_str)
|
||||
skill_str = \
|
||||
html_skills_search(actor_str,
|
||||
self.server.translate,
|
||||
base_dir,
|
||||
search_str,
|
||||
self.server.instance_only_skills_search,
|
||||
64)
|
||||
64, nickname, domain,
|
||||
self.server.theme_name,
|
||||
self.server.access_keys)
|
||||
if skill_str:
|
||||
msg = skill_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -4081,7 +4084,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.cw_lists,
|
||||
self.server.lists_enabled,
|
||||
timezone, bold_reading,
|
||||
self.server.dogwhistles)
|
||||
self.server.dogwhistles,
|
||||
self.server.access_keys)
|
||||
if history_str:
|
||||
msg = history_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -4162,7 +4166,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.cw_lists,
|
||||
self.server.lists_enabled,
|
||||
timezone, bold_reading,
|
||||
self.server.dogwhistles)
|
||||
self.server.dogwhistles,
|
||||
self.server.access_keys)
|
||||
if bookmarks_str:
|
||||
msg = bookmarks_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -4355,10 +4360,13 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
search_str = \
|
||||
search_str.replace(' emoji', '')
|
||||
# emoji search
|
||||
nickname = get_nickname_from_actor(actor_str)
|
||||
emoji_str = \
|
||||
html_search_emoji(self.server.translate,
|
||||
base_dir,
|
||||
search_str)
|
||||
base_dir, search_str,
|
||||
nickname, domain,
|
||||
self.server.theme_name,
|
||||
self.server.access_keys)
|
||||
if emoji_str:
|
||||
msg = emoji_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -4371,6 +4379,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# wanted items search
|
||||
shared_items_federated_domains = \
|
||||
self.server.shared_items_federated_domains
|
||||
nickname = get_nickname_from_actor(actor_str)
|
||||
wanted_items_str = \
|
||||
html_search_shared_items(self.server.translate,
|
||||
base_dir,
|
||||
|
@ -4380,7 +4389,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
domain_full,
|
||||
actor_str, calling_domain,
|
||||
shared_items_federated_domains,
|
||||
'wanted')
|
||||
'wanted', nickname, domain,
|
||||
self.server.theme_name,
|
||||
self.server.access_keys)
|
||||
if wanted_items_str:
|
||||
msg = wanted_items_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
@ -4393,6 +4404,7 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
# shared items search
|
||||
shared_items_federated_domains = \
|
||||
self.server.shared_items_federated_domains
|
||||
nickname = get_nickname_from_actor(actor_str)
|
||||
shared_items_str = \
|
||||
html_search_shared_items(self.server.translate,
|
||||
base_dir,
|
||||
|
@ -4402,7 +4414,9 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
domain_full,
|
||||
actor_str, calling_domain,
|
||||
shared_items_federated_domains,
|
||||
'shares')
|
||||
'shares', nickname, domain,
|
||||
self.server.theme_name,
|
||||
self.server.access_keys)
|
||||
if shared_items_str:
|
||||
msg = shared_items_str.encode('utf-8')
|
||||
msglen = len(msg)
|
||||
|
|
5
tests.py
5
tests.py
|
@ -4697,7 +4697,7 @@ def _test_reply_to_public_post(base_dir: str) -> None:
|
|||
# print(str(reply))
|
||||
expected_str = \
|
||||
'<p><span class=\"h-card\">' + \
|
||||
'<a href=\"https://rat.site/@ninjarodent\" tabindex="10" ' + \
|
||||
'<a href=\"https://rat.site/users/ninjarodent\" tabindex="10" ' + \
|
||||
'class=\"u-url mention\">@<span>ninjarodent</span>' + \
|
||||
'</a></span> This is a test.</p>'
|
||||
if reply['object']['content'] != expected_str:
|
||||
|
@ -4707,7 +4707,8 @@ def _test_reply_to_public_post(base_dir: str) -> None:
|
|||
reply['object']['contentMap'][system_language] = reply['object']['content']
|
||||
assert reply['object']['tag'][0]['type'] == 'Mention'
|
||||
assert reply['object']['tag'][0]['name'] == '@ninjarodent@rat.site'
|
||||
assert reply['object']['tag'][0]['href'] == 'https://rat.site/@ninjarodent'
|
||||
assert reply['object']['tag'][0]['href'] == \
|
||||
'https://rat.site/users/ninjarodent'
|
||||
assert len(reply['object']['to']) == 1
|
||||
assert reply['object']['to'][0].endswith('#Public')
|
||||
assert len(reply['object']['cc']) >= 1
|
||||
|
|
|
@ -44,7 +44,9 @@ from webapp_hashtagswarm import html_hash_tag_swarm
|
|||
from maps import html_hashtag_maps
|
||||
|
||||
|
||||
def html_search_emoji(translate: {}, base_dir: str, search_str: str) -> str:
|
||||
def html_search_emoji(translate: {}, base_dir: str, search_str: str,
|
||||
nickname: str, domain: str, theme: str,
|
||||
access_keys: {}) -> str:
|
||||
"""Search results for emoji
|
||||
"""
|
||||
# emoji.json is generated so that it can be customized and the changes
|
||||
|
@ -66,6 +68,24 @@ def html_search_emoji(translate: {}, base_dir: str, search_str: str) -> str:
|
|||
get_config_param(base_dir, 'instanceTitle')
|
||||
emoji_form = \
|
||||
html_header_with_external_style(css_filename, instance_title, None)
|
||||
|
||||
# show top banner
|
||||
if nickname and domain and theme:
|
||||
banner_file, _ = \
|
||||
get_banner_file(base_dir, nickname, domain, theme)
|
||||
emoji_form += \
|
||||
'<header>\n' + \
|
||||
'<a href="/users/' + nickname + '/search" title="' + \
|
||||
translate['Search and follow'] + '" alt="' + \
|
||||
translate['Search and follow'] + '" ' + \
|
||||
'aria-flowto="containerHeader" tabindex="1" accesskey="' + \
|
||||
access_keys['menuSearch'] + '">\n'
|
||||
emoji_form += \
|
||||
'<img loading="lazy" decoding="async" ' + \
|
||||
'class="timeline-banner" alt="" ' + \
|
||||
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
|
||||
'</header>\n'
|
||||
|
||||
emoji_form += '<center><h1>' + \
|
||||
translate['Emoji Search'] + \
|
||||
'</h1></center>'
|
||||
|
@ -229,7 +249,9 @@ def html_search_shared_items(translate: {},
|
|||
domain_full: str, actor: str,
|
||||
calling_domain: str,
|
||||
shared_items_federated_domains: [],
|
||||
shares_file_type: str) -> str:
|
||||
shares_file_type: str,
|
||||
nickname: str, domain: str, theme_name: str,
|
||||
access_keys: {}) -> str:
|
||||
"""Search results for shared items
|
||||
"""
|
||||
curr_page = 1
|
||||
|
@ -250,6 +272,24 @@ def html_search_shared_items(translate: {},
|
|||
title_str = translate['Shared Items Search']
|
||||
else:
|
||||
title_str = translate['Wanted Items Search']
|
||||
|
||||
# show top banner
|
||||
if nickname and domain and theme_name:
|
||||
banner_file, _ = \
|
||||
get_banner_file(base_dir, nickname, domain, theme_name)
|
||||
shared_items_form += \
|
||||
'<header>\n' + \
|
||||
'<a href="/users/' + nickname + '/search" title="' + \
|
||||
translate['Search and follow'] + '" alt="' + \
|
||||
translate['Search and follow'] + '" ' + \
|
||||
'aria-flowto="containerHeader" tabindex="1" accesskey="' + \
|
||||
access_keys['menuSearch'] + '">\n'
|
||||
shared_items_form += \
|
||||
'<img loading="lazy" decoding="async" ' + \
|
||||
'class="timeline-banner" alt="" ' + \
|
||||
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
|
||||
'</header>\n'
|
||||
|
||||
shared_items_form += \
|
||||
'<center><h1>' + \
|
||||
'<a href="' + actor + '/search">' + title_str + '</a></h1></center>'
|
||||
|
@ -482,7 +522,9 @@ def html_search(translate: {}, base_dir: str, path: str, domain: str,
|
|||
|
||||
def html_skills_search(actor: str, translate: {}, base_dir: str,
|
||||
skillsearch: str, instance_only: bool,
|
||||
posts_per_page: int) -> str:
|
||||
posts_per_page: int,
|
||||
nickname: str, domain: str, theme_name: str,
|
||||
access_keys: {}) -> str:
|
||||
"""Show a page containing search results for a skill
|
||||
"""
|
||||
if skillsearch.startswith('*'):
|
||||
|
@ -576,6 +618,24 @@ def html_skills_search(actor: str, translate: {}, base_dir: str,
|
|||
get_config_param(base_dir, 'instanceTitle')
|
||||
skill_search_form = \
|
||||
html_header_with_external_style(css_filename, instance_title, None)
|
||||
|
||||
# show top banner
|
||||
if nickname and domain and theme_name:
|
||||
banner_file, _ = \
|
||||
get_banner_file(base_dir, nickname, domain, theme_name)
|
||||
skill_search_form += \
|
||||
'<header>\n' + \
|
||||
'<a href="/users/' + nickname + '/search" title="' + \
|
||||
translate['Search and follow'] + '" alt="' + \
|
||||
translate['Search and follow'] + '" ' + \
|
||||
'aria-flowto="containerHeader" tabindex="1" accesskey="' + \
|
||||
access_keys['menuSearch'] + '">\n'
|
||||
skill_search_form += \
|
||||
'<img loading="lazy" decoding="async" ' + \
|
||||
'class="timeline-banner" alt="" ' + \
|
||||
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
|
||||
'</header>\n'
|
||||
|
||||
skill_search_form += \
|
||||
'<center><h1><a href = "' + actor + '/search">' + \
|
||||
translate['Skills search'] + ': ' + \
|
||||
|
@ -635,7 +695,7 @@ def html_history_search(translate: {}, base_dir: str,
|
|||
cw_lists: {},
|
||||
lists_enabled: str,
|
||||
timezone: str, bold_reading: bool,
|
||||
dogwhistles: {}) -> str:
|
||||
dogwhistles: {}, access_keys: {}) -> str:
|
||||
"""Show a page containing search results for your post history
|
||||
"""
|
||||
if historysearch.startswith("'"):
|
||||
|
@ -663,6 +723,22 @@ def html_history_search(translate: {}, base_dir: str,
|
|||
if box_name == 'bookmarks':
|
||||
history_search_title = '🔍 ' + translate['Bookmarks']
|
||||
|
||||
if nickname and domain and theme_name:
|
||||
banner_file, _ = \
|
||||
get_banner_file(base_dir, nickname, domain, theme_name)
|
||||
history_search_form += \
|
||||
'<header>\n' + \
|
||||
'<a href="/users/' + nickname + '/search" title="' + \
|
||||
translate['Search and follow'] + '" alt="' + \
|
||||
translate['Search and follow'] + '" ' + \
|
||||
'aria-flowto="containerHeader" tabindex="1" accesskey="' + \
|
||||
access_keys['menuSearch'] + '">\n'
|
||||
history_search_form += \
|
||||
'<img loading="lazy" decoding="async" ' + \
|
||||
'class="timeline-banner" alt="" ' + \
|
||||
'src="/users/' + nickname + '/' + banner_file + '" /></a>\n' + \
|
||||
'</header>\n'
|
||||
|
||||
history_search_form += \
|
||||
'<center><h1><a href="' + actor + '/search">' + \
|
||||
history_search_title + '</a></h1></center>'
|
||||
|
|
Loading…
Reference in New Issue