mirror of
https://gitlab.com/bashrc2/epicyon
synced 2026-11-02 02:40:12 +00:00
Ensure that number of hashtags stored per post is limited
This commit is contained in:
1 parent
68eab5b01c
commit
9fa6571502
7 files changed
+36
-22
No files matched your search
+2
-1
@@ -168,7 +168,8 @@ def post_to_outbox(self, message_json: {}, version: str,
|
||||
self.server.auto_cw_cache,
|
||||
self.server.block_federated,
|
||||
self.server.mitm_servers,
|
||||
self.server.instance_software)
|
||||
self.server.instance_software,
|
||||
self.server.max_hashtags)
|
||||
|
||||
|
||||
def _get_outbox_thread_index(self, nickname: str,
|
||||
|
||||
+4
-2
@@ -2347,7 +2347,8 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||
server.block_military,
|
||||
server.block_government,
|
||||
server.block_bluesky,
|
||||
server.block_nostr):
|
||||
server.block_nostr,
|
||||
max_hashtags):
|
||||
if debug:
|
||||
print('DEBUG: Announce accepted from ' + actor)
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
@@ -2832,7 +2833,8 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||
|
||||
store_hash_tags(base_dir, handle_name, domain,
|
||||
http_prefix, domain_full,
|
||||
post_json_object, translate, session)
|
||||
post_json_object, translate, session,
|
||||
max_hashtags)
|
||||
fitness_performance(inbox_start_time,
|
||||
server.fitness,
|
||||
'INBOX', 'store_hash_tags',
|
||||
|
||||
@@ -2109,7 +2109,8 @@ def receive_announce(recent_posts_cache: {},
|
||||
block_military: {},
|
||||
block_government: {},
|
||||
block_bluesky: {},
|
||||
block_nostr: {}) -> bool:
|
||||
block_nostr: {},
|
||||
max_hashtags: int) -> bool:
|
||||
"""Receives an announce activity within the POST section of HTTPServer
|
||||
"""
|
||||
if message_json['type'] != 'Announce':
|
||||
@@ -2392,7 +2393,8 @@ def receive_announce(recent_posts_cache: {},
|
||||
|
||||
store_hash_tags(base_dir, nickname, domain,
|
||||
http_prefix, domain_full,
|
||||
post_json_object, translate, session)
|
||||
post_json_object, translate, session,
|
||||
max_hashtags)
|
||||
# Try to obtain the actor for this person
|
||||
# so that their avatar can be shown
|
||||
lookup_actor = None
|
||||
|
||||
+14
-12
@@ -293,7 +293,7 @@ def hashtag_rule_tree(operators: [],
|
||||
def _hashtag_add(base_dir: str, http_prefix: str, domain_full: str,
|
||||
post_json_object: {},
|
||||
action_str: str, hashtags: [], system_language: str,
|
||||
translate: {}, session) -> None:
|
||||
translate: {}, session, max_hashtags: int) -> None:
|
||||
"""Adds a hashtag via a hashtag rule
|
||||
"""
|
||||
add_hashtag = action_str.split('add ', 1)[1].strip()
|
||||
@@ -341,9 +341,8 @@ def _hashtag_add(base_dir: str, http_prefix: str, domain_full: str,
|
||||
domain = domain_full
|
||||
if ':' in domain:
|
||||
domain = remove_domain_port(domain)
|
||||
store_hash_tags(base_dir, 'news', domain,
|
||||
http_prefix, domain_full,
|
||||
post_json_object, translate, session)
|
||||
store_hash_tags(base_dir, 'news', domain, http_prefix, domain_full,
|
||||
post_json_object, translate, session, max_hashtags)
|
||||
|
||||
|
||||
def _hashtag_remove(http_prefix: str, domain_full: str, post_json_object: {},
|
||||
@@ -384,7 +383,8 @@ def _newswire_hashtag_processing(base_dir: str, post_json_object: {},
|
||||
domain: str, port: int,
|
||||
moderated: bool, url: str,
|
||||
system_language: str,
|
||||
translate: {}, session) -> bool:
|
||||
translate: {}, session,
|
||||
max_hashtags: int) -> bool:
|
||||
"""Applies hashtag rules to a news post.
|
||||
Returns true if the post should be saved to the news timeline
|
||||
of this instance
|
||||
@@ -433,7 +433,8 @@ def _newswire_hashtag_processing(base_dir: str, post_json_object: {},
|
||||
# add a hashtag
|
||||
_hashtag_add(base_dir, http_prefix, domain_full,
|
||||
post_json_object, action_str, hashtags,
|
||||
system_language, translate, session)
|
||||
system_language, translate, session,
|
||||
max_hashtags)
|
||||
elif action_str.startswith('remove '):
|
||||
# remove a hashtag
|
||||
_hashtag_remove(http_prefix, domain_full, post_json_object,
|
||||
@@ -554,7 +555,8 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
|
||||
content_license_url: str,
|
||||
media_license_url: str,
|
||||
media_creator: str,
|
||||
session, debug: bool) -> None:
|
||||
session, debug: bool,
|
||||
max_hashtags: int) -> None:
|
||||
"""Converts rss items in a newswire into posts
|
||||
"""
|
||||
if not newswire:
|
||||
@@ -705,7 +707,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
|
||||
_newswire_hashtag_processing(base_dir, blog, hashtags,
|
||||
http_prefix, domain, port,
|
||||
moderated, url, system_language,
|
||||
translate, session)
|
||||
translate, session, max_hashtags)
|
||||
|
||||
# save the post and update the index
|
||||
if save_post:
|
||||
@@ -744,9 +746,8 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str,
|
||||
if tag not in newswire[original_date_str][6]:
|
||||
newswire[original_date_str][6].append(tag)
|
||||
|
||||
store_hash_tags(base_dir, 'news', domain,
|
||||
http_prefix, domain_full,
|
||||
blog, translate, session)
|
||||
store_hash_tags(base_dir, 'news', domain, http_prefix, domain_full,
|
||||
blog, translate, session, max_hashtags)
|
||||
|
||||
clear_from_post_caches(base_dir, recent_posts_cache, post_id)
|
||||
if save_json(blog, filename):
|
||||
@@ -852,7 +853,8 @@ def run_newswire_daemon(base_dir: str, httpd,
|
||||
httpd.low_bandwidth,
|
||||
httpd.content_license_url,
|
||||
httpd.content_license_url, '',
|
||||
httpd.session, httpd.debug)
|
||||
httpd.session, httpd.debug,
|
||||
httpd.max_hashtags)
|
||||
print('Newswire feed converted to ActivityPub')
|
||||
|
||||
if httpd.max_news_posts > 0:
|
||||
|
||||
+4
-2
@@ -316,7 +316,8 @@ def post_message_to_outbox(session, translate: {},
|
||||
auto_cw_cache: {},
|
||||
block_federated: [],
|
||||
mitm_servers: [],
|
||||
instance_software: {}) -> bool:
|
||||
instance_software: {},
|
||||
max_hashtags: int) -> bool:
|
||||
"""post is received by the outbox
|
||||
Client to server message post
|
||||
https://www.w3.org/TR/activitypub/#client-to-server-outbox-delivery
|
||||
@@ -564,7 +565,8 @@ def post_message_to_outbox(session, translate: {},
|
||||
|
||||
store_hash_tags(base_dir, post_to_nickname, domain,
|
||||
http_prefix, domain_full,
|
||||
message_json, translate, session)
|
||||
message_json, translate, session,
|
||||
max_hashtags)
|
||||
|
||||
# if this is a blog post or an event then save to its own box
|
||||
if message_json['type'] == 'Create':
|
||||
|
||||
+2
-1
@@ -175,7 +175,8 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
|
||||
httpd.auto_cw_cache,
|
||||
httpd.block_federated,
|
||||
httpd.mitm_servers,
|
||||
httpd.instance_software):
|
||||
httpd.instance_software,
|
||||
httpd.max_hashtags):
|
||||
index_lines.remove(line)
|
||||
ex_text = \
|
||||
'EX: _update_post_schedule unable to delete ' + \
|
||||
|
||||
@@ -416,7 +416,7 @@ def _store_tag_name(base_dir: str, nickname: str,
|
||||
def store_hash_tags(base_dir: str, nickname: str, domain: str,
|
||||
http_prefix: str, domain_full: str,
|
||||
post_json_object: {}, translate: {},
|
||||
session) -> None:
|
||||
session, max_hashtags: int) -> None:
|
||||
"""Extracts hashtags from an incoming post and updates the
|
||||
relevant tags files.
|
||||
"""
|
||||
@@ -484,12 +484,14 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str,
|
||||
map_links, published,
|
||||
tag_maps_dir):
|
||||
hashtags_ctr += 1
|
||||
if hashtags_ctr >= max_hashtags:
|
||||
break
|
||||
|
||||
# treat event categories as hashtags
|
||||
# See https://codeberg.org/fediverse/
|
||||
# fep/src/branch/main/fep/8a8e/fep-8a8e.md
|
||||
event_category_str = get_category_from_post(post_json_object, translate)
|
||||
if event_category_str:
|
||||
if event_category_str and hashtags_ctr < max_hashtags:
|
||||
if ', ' in event_category_str:
|
||||
event_category_list = event_category_str.split(', ')
|
||||
else:
|
||||
@@ -506,6 +508,8 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str,
|
||||
map_links, published,
|
||||
tag_maps_dir):
|
||||
hashtags_ctr += 1
|
||||
if hashtags_ctr >= max_hashtags:
|
||||
break
|
||||
|
||||
# if some hashtags were found then recalculate the swarm
|
||||
# ready for later display
|
||||
|
||||
Reference in new issue
Block a user