mirror of https://gitlab.com/bashrc2/epicyon
More general
parent
3e1af39257
commit
1d099e7dea
53
utils.py
53
utils.py
|
@ -1265,23 +1265,42 @@ def dangerous_svg(content: str, allow_local_network_access: bool) -> bool:
|
||||||
separators, invalid_strings)
|
separators, invalid_strings)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_statuses_list() -> []:
|
||||||
|
"""Returns a list of statuses path strings
|
||||||
|
"""
|
||||||
|
return ('/statuses/', '/objects/', '/p/')
|
||||||
|
|
||||||
|
|
||||||
|
def contains_statuses(url: str) -> bool:
|
||||||
|
"""Whether the given url contains /statuses/
|
||||||
|
"""
|
||||||
|
statuses_list = _get_statuses_list()
|
||||||
|
for status_str in statuses_list:
|
||||||
|
if status_str in url:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_actor_from_post_id(post_id: str) -> str:
|
def get_actor_from_post_id(post_id: str) -> str:
|
||||||
"""Returns an actor url from a post id
|
"""Returns an actor url from a post id containing /statuses/ or equivalent
|
||||||
eg. https://somedomain/users/nick/statuses/123 becomes
|
eg. https://somedomain/users/nick/statuses/123 becomes
|
||||||
https://somedomain/users/nick
|
https://somedomain/users/nick
|
||||||
"""
|
"""
|
||||||
actor = post_id
|
actor = post_id
|
||||||
if has_users_path(actor):
|
statuses_list = _get_statuses_list()
|
||||||
if '/statuses/' in actor:
|
pixelfed_style_statuses = ['/p/']
|
||||||
actor = actor.split('/statuses/')[0]
|
for status_str in statuses_list:
|
||||||
elif '/objects/' in actor:
|
if status_str in pixelfed_style_statuses:
|
||||||
actor = actor.split('/objects/')[0]
|
# pixelfed style post id
|
||||||
elif '/p/' in actor:
|
nick = actor.split(status_str)[1]
|
||||||
# pixelfed style post id
|
if '/' in nick:
|
||||||
nick = actor.split('/p/')[1]
|
nick = nick.split('/')[0]
|
||||||
if '/' in nick:
|
actor = actor.split(status_str)[0] + '/users/' + nick
|
||||||
nick = nick.split('/')[0]
|
break
|
||||||
actor = actor.split('/p/')[0] + '/users/' + nick
|
if status_str in actor:
|
||||||
|
if has_users_path(actor):
|
||||||
|
actor = actor.split(status_str)[0]
|
||||||
|
break
|
||||||
return actor
|
return actor
|
||||||
|
|
||||||
|
|
||||||
|
@ -4452,13 +4471,3 @@ def ap_proxy_type(json_object: {}) -> str:
|
||||||
if isinstance(proxy_dict['protocol'], str):
|
if isinstance(proxy_dict['protocol'], str):
|
||||||
return proxy_dict['protocol']
|
return proxy_dict['protocol']
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def contains_statuses(url: str) -> bool:
|
|
||||||
"""Whether the given url contains /statuses/
|
|
||||||
"""
|
|
||||||
statuses_list = ('/statuses/', '/objects/', '/p/')
|
|
||||||
for status_str in statuses_list:
|
|
||||||
if status_str in url:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
Loading…
Reference in New Issue