mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
633bf13053
29
daemon.py
29
daemon.py
|
@ -462,7 +462,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
peertube_instances: [],
|
||||
theme_name: str, max_like_count: int,
|
||||
cw_lists: {}, dogwhistles: {},
|
||||
min_images_for_accounts: []) -> None:
|
||||
min_images_for_accounts: [],
|
||||
max_hashtags: int) -> None:
|
||||
"""When an edited post is created this assigns
|
||||
a published and updated date to it, and uses
|
||||
the previous id
|
||||
|
@ -509,7 +510,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
peertube_instances,
|
||||
theme_name, max_like_count,
|
||||
cw_lists, dogwhistles,
|
||||
min_images_for_accounts)
|
||||
min_images_for_accounts,
|
||||
max_hashtags)
|
||||
|
||||
# update the index
|
||||
id_str = edited_postid.split('/')[-1]
|
||||
|
@ -1135,8 +1137,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
'<div style="font-size: 128px; ' \
|
||||
'text-align: center; font-variant: ' \
|
||||
'small-caps;"><p role="alert">' + http_description + '</p></div>' \
|
||||
'<div style="text-align: center;">' + long_description + '</div>' \
|
||||
'</body></html>'
|
||||
'<div style="text-align: center;" aria-live="polite">' + \
|
||||
long_description + '</div></body></html>'
|
||||
msg = msg.encode('utf-8')
|
||||
self.send_response(http_code)
|
||||
self.send_header('Content-Type', 'text/html; charset=utf-8')
|
||||
|
@ -19579,7 +19581,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.max_like_count,
|
||||
self.server.cw_lists,
|
||||
self.server.dogwhistles,
|
||||
min_images_for_accounts)
|
||||
min_images_for_accounts,
|
||||
self.server.max_hashtags)
|
||||
print('DEBUG: sending edited public post ' +
|
||||
str(message_json))
|
||||
if fields['schedulePost']:
|
||||
|
@ -19882,7 +19885,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.max_like_count,
|
||||
self.server.cw_lists,
|
||||
self.server.dogwhistles,
|
||||
min_images_for_accounts)
|
||||
min_images_for_accounts,
|
||||
self.server.max_hashtags)
|
||||
print('DEBUG: sending edited unlisted post ' +
|
||||
str(message_json))
|
||||
|
||||
|
@ -19991,7 +19995,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.max_like_count,
|
||||
self.server.cw_lists,
|
||||
self.server.dogwhistles,
|
||||
min_images_for_accounts)
|
||||
min_images_for_accounts,
|
||||
self.server.max_hashtags)
|
||||
print('DEBUG: sending edited followers post ' +
|
||||
str(message_json))
|
||||
|
||||
|
@ -20114,7 +20119,8 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
self.server.max_like_count,
|
||||
self.server.cw_lists,
|
||||
self.server.dogwhistles,
|
||||
min_images_for_accounts)
|
||||
min_images_for_accounts,
|
||||
self.server.max_hashtags)
|
||||
print('DEBUG: sending edited dm post ' +
|
||||
str(message_json))
|
||||
|
||||
|
@ -21633,7 +21639,8 @@ def load_tokens(base_dir: str, tokens_dict: {}, tokens_lookup: {}) -> None:
|
|||
break
|
||||
|
||||
|
||||
def run_daemon(map_format: str,
|
||||
def run_daemon(max_hashtags: int,
|
||||
map_format: str,
|
||||
clacks: str,
|
||||
preferred_podcast_formats: [],
|
||||
check_actor_timeout: int,
|
||||
|
@ -22206,6 +22213,7 @@ def run_daemon(map_format: str,
|
|||
|
||||
httpd.max_mentions = max_mentions
|
||||
httpd.max_emoji = max_emoji
|
||||
httpd.max_hashtags = max_hashtags
|
||||
|
||||
print('THREAD: Creating inbox queue')
|
||||
httpd.thrInboxQueue = \
|
||||
|
@ -22237,7 +22245,8 @@ def run_daemon(map_format: str,
|
|||
httpd.max_like_count,
|
||||
httpd.signing_priv_key_pem,
|
||||
httpd.default_reply_interval_hrs,
|
||||
httpd.cw_lists), daemon=True)
|
||||
httpd.cw_lists,
|
||||
httpd.max_hashtags), daemon=True)
|
||||
|
||||
print('THREAD: Creating scheduled post thread')
|
||||
httpd.thrPostSchedule = \
|
||||
|
|
|
@ -592,6 +592,9 @@ def _command_options() -> None:
|
|||
parser.add_argument('--max_like_count', dest='max_like_count', type=int,
|
||||
default=10,
|
||||
help='Maximum number of likes displayed on a post')
|
||||
parser.add_argument('--max_hashtags', dest='max_hashtags', type=int,
|
||||
default=20,
|
||||
help='Maximum number of hashtags on a post')
|
||||
parser.add_argument('--votingtime', dest='votingtime', type=int,
|
||||
default=1440,
|
||||
help='Time to vote on newswire items in minutes')
|
||||
|
@ -3672,7 +3675,8 @@ def _command_options() -> None:
|
|||
if __name__ == "__main__":
|
||||
argb2, opt2 = _command_options()
|
||||
print('allowdeletion: ' + str(argb2.allowdeletion))
|
||||
run_daemon(argb2.mapFormat,
|
||||
run_daemon(argb2.max_hashtags,
|
||||
argb2.mapFormat,
|
||||
argb2.clacks,
|
||||
opt2['preferred_podcast_formats'],
|
||||
argb2.check_actor_timeout,
|
||||
|
|
41
inbox.py
41
inbox.py
|
@ -1155,7 +1155,8 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {},
|
|||
peertube_instances: [],
|
||||
theme_name: str, max_like_count: int,
|
||||
cw_lists: {}, dogwhistles: {},
|
||||
min_images_for_accounts: []) -> bool:
|
||||
min_images_for_accounts: [],
|
||||
max_hashtags: int) -> bool:
|
||||
"""A post was edited
|
||||
"""
|
||||
if not has_object_dict(message_json):
|
||||
|
@ -1181,7 +1182,8 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {},
|
|||
message_json, max_mentions, max_emoji,
|
||||
allow_local_network_access, debug,
|
||||
system_language, http_prefix,
|
||||
domain_full, person_cache):
|
||||
domain_full, person_cache,
|
||||
max_hashtags):
|
||||
print('EDITPOST: contains invalid content' + str(message_json))
|
||||
return False
|
||||
|
||||
|
@ -1304,7 +1306,8 @@ def _receive_update_activity(recent_posts_cache: {}, session, base_dir: str,
|
|||
peertube_instances: [],
|
||||
theme_name: str, max_like_count: int,
|
||||
cw_lists: {}, dogwhistles: {},
|
||||
min_images_for_accounts: []) -> bool:
|
||||
min_images_for_accounts: [],
|
||||
max_hashtags: int) -> bool:
|
||||
|
||||
"""Receives an Update activity within the POST section of HTTPServer
|
||||
"""
|
||||
|
@ -1345,7 +1348,8 @@ def _receive_update_activity(recent_posts_cache: {}, session, base_dir: str,
|
|||
peertube_instances,
|
||||
theme_name, max_like_count,
|
||||
cw_lists, dogwhistles,
|
||||
min_images_for_accounts):
|
||||
min_images_for_accounts,
|
||||
max_hashtags):
|
||||
print('EDITPOST: received ' + message_json['object']['id'])
|
||||
return True
|
||||
else:
|
||||
|
@ -2869,12 +2873,19 @@ def _estimate_number_of_emoji(content: str) -> int:
|
|||
return content.count(' :')
|
||||
|
||||
|
||||
def _estimate_number_of_hashtags(content: str) -> int:
|
||||
"""Returns a rough estimate of the number of hashtags
|
||||
"""
|
||||
return content.count('>#<')
|
||||
|
||||
|
||||
def _valid_post_content(base_dir: str, nickname: str, domain: str,
|
||||
message_json: {}, max_mentions: int, max_emoji: int,
|
||||
allow_local_network_access: bool, debug: bool,
|
||||
system_language: str,
|
||||
http_prefix: str, domain_full: str,
|
||||
person_cache: {}) -> bool:
|
||||
person_cache: {},
|
||||
max_hashtags: int) -> bool:
|
||||
"""Is the content of a received post valid?
|
||||
Check for bad html
|
||||
Check for hellthreads
|
||||
|
@ -2962,6 +2973,12 @@ def _valid_post_content(base_dir: str, nickname: str, domain: str,
|
|||
print('REJECT EMOJI OVERLOAD: Too many emoji in post - ' +
|
||||
content_str)
|
||||
return False
|
||||
if _estimate_number_of_hashtags(content_str) > max_hashtags:
|
||||
if message_json['object'].get('id'):
|
||||
print('REJECT HASHTAG OVERLOAD: ' + message_json['object']['id'])
|
||||
print('REJECT HASHTAG OVERLOAD: Too many hashtags in post - ' +
|
||||
content_str)
|
||||
return False
|
||||
# check number of tags
|
||||
if message_json['object'].get('tag'):
|
||||
if not isinstance(message_json['object']['tag'], list):
|
||||
|
@ -3981,7 +3998,8 @@ def _inbox_after_initial(server, inbox_start_time,
|
|||
content_license_url: str,
|
||||
languages_understood: [],
|
||||
mitm: bool, bold_reading: bool,
|
||||
dogwhistles: {}) -> bool:
|
||||
dogwhistles: {},
|
||||
max_hashtags: int) -> bool:
|
||||
""" Anything which needs to be done after initial checks have passed
|
||||
"""
|
||||
# if this is a clearnet instance then replace any onion/i2p
|
||||
|
@ -4294,7 +4312,8 @@ def _inbox_after_initial(server, inbox_start_time,
|
|||
post_json_object, max_mentions, max_emoji,
|
||||
allow_local_network_access, debug,
|
||||
system_language, http_prefix,
|
||||
domain_full, person_cache):
|
||||
domain_full, person_cache,
|
||||
max_hashtags):
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', '_valid_post_content',
|
||||
debug)
|
||||
|
@ -5222,7 +5241,7 @@ def run_inbox_queue(server,
|
|||
theme_name: str, system_language: str,
|
||||
max_like_count: int, signing_priv_key_pem: str,
|
||||
default_reply_interval_hrs: int,
|
||||
cw_lists: {}) -> None:
|
||||
cw_lists: {}, max_hashtags: int) -> None:
|
||||
"""Processes received items and moves them to the appropriate
|
||||
directories
|
||||
"""
|
||||
|
@ -5681,7 +5700,8 @@ def run_inbox_queue(server,
|
|||
peertube_instances,
|
||||
theme_name, max_like_count,
|
||||
cw_lists, dogwhistles,
|
||||
server.min_images_for_accounts):
|
||||
server.min_images_for_accounts,
|
||||
max_hashtags):
|
||||
if debug:
|
||||
print('Queue: Update accepted from ' + key_id)
|
||||
if os.path.isfile(queue_filename):
|
||||
|
@ -5809,7 +5829,8 @@ def run_inbox_queue(server,
|
|||
cw_lists, lists_enabled,
|
||||
content_license_url,
|
||||
languages_understood, mitm,
|
||||
bold_reading, dogwhistles)
|
||||
bold_reading, dogwhistles,
|
||||
max_hashtags)
|
||||
fitness_performance(inbox_start_time, server.fitness,
|
||||
'INBOX', 'handle_after_initial',
|
||||
debug)
|
||||
|
|
12
tests.py
12
tests.py
|
@ -844,8 +844,9 @@ def create_server_alice(path: str, domain: str, port: int,
|
|||
preferred_podcast_formats = None
|
||||
clacks = None
|
||||
map_format = 'gpx'
|
||||
max_hashtags = 20
|
||||
print('Server running: Alice')
|
||||
run_daemon(map_format,
|
||||
run_daemon(max_hashtags, map_format,
|
||||
clacks, preferred_podcast_formats,
|
||||
check_actor_timeout,
|
||||
crawlers_allowed,
|
||||
|
@ -1007,8 +1008,9 @@ def create_server_bob(path: str, domain: str, port: int,
|
|||
preferred_podcast_formats = None
|
||||
clacks = None
|
||||
map_format = 'gpx'
|
||||
max_hashtags = 20
|
||||
print('Server running: Bob')
|
||||
run_daemon(map_format,
|
||||
run_daemon(max_hashtags, map_format,
|
||||
clacks, preferred_podcast_formats,
|
||||
check_actor_timeout,
|
||||
crawlers_allowed,
|
||||
|
@ -1092,8 +1094,9 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [],
|
|||
preferred_podcast_formats = None
|
||||
clacks = None
|
||||
map_format = 'gpx'
|
||||
max_hashtags = 20
|
||||
print('Server running: Eve')
|
||||
run_daemon(map_format,
|
||||
run_daemon(max_hashtags, map_format,
|
||||
clacks, preferred_podcast_formats,
|
||||
check_actor_timeout,
|
||||
crawlers_allowed,
|
||||
|
@ -1179,8 +1182,9 @@ def create_server_group(path: str, domain: str, port: int,
|
|||
preferred_podcast_formats = None
|
||||
clacks = None
|
||||
map_format = 'gpx'
|
||||
max_hashtags = 20
|
||||
print('Server running: Group')
|
||||
run_daemon(map_format,
|
||||
run_daemon(max_hashtags, map_format,
|
||||
clacks, preferred_podcast_formats,
|
||||
check_actor_timeout,
|
||||
crawlers_allowed,
|
||||
|
|
Loading…
Reference in New Issue