merge-requests/30/head
Bob Mottram 2022-05-30 13:45:47 +01:00
parent a40126027e
commit 611c6cab17
2 changed files with 22 additions and 22 deletions

View File

@ -25,54 +25,54 @@ from utils import has_object_string_type
def _create_accept_reject(base_dir: str, federation_list: [], def _create_accept_reject(base_dir: str, federation_list: [],
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
toUrl: str, ccUrl: str, http_prefix: str, to_url: str, cc_url: str, http_prefix: str,
objectJson: {}, acceptType: str) -> {}: object_json: {}, accept_type: str) -> {}:
"""Accepts or rejects something (eg. a follow request or offer) """Accepts or rejects something (eg. a follow request or offer)
Typically toUrl will be https://www.w3.org/ns/activitystreams#Public Typically to_url will be https://www.w3.org/ns/activitystreams#Public
and ccUrl might be a specific person favorited or repeated and and cc_url might be a specific person favorited or repeated and
the followers url objectUrl is typically the url of the message, the followers url objectUrl is typically the url of the message,
corresponding to url or atomUri in createPostBase corresponding to url or atomUri in createPostBase
""" """
if not objectJson.get('actor'): if not object_json.get('actor'):
return None return None
if not url_permitted(objectJson['actor'], federation_list): if not url_permitted(object_json['actor'], federation_list):
return None return None
domain = get_full_domain(domain, port) domain = get_full_domain(domain, port)
new_accept = { new_accept = {
"@context": "https://www.w3.org/ns/activitystreams", "@context": "https://www.w3.org/ns/activitystreams",
'type': acceptType, 'type': accept_type,
'actor': local_actor_url(http_prefix, nickname, domain), 'actor': local_actor_url(http_prefix, nickname, domain),
'to': [toUrl], 'to': [to_url],
'cc': [], 'cc': [],
'object': objectJson 'object': object_json
} }
if ccUrl: if cc_url:
if len(ccUrl) > 0: if len(cc_url) > 0:
new_accept['cc'] = [ccUrl] new_accept['cc'] = [cc_url]
return new_accept return new_accept
def create_accept(base_dir: str, federation_list: [], def create_accept(base_dir: str, federation_list: [],
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
toUrl: str, ccUrl: str, http_prefix: str, to_url: str, cc_url: str, http_prefix: str,
objectJson: {}) -> {}: object_json: {}) -> {}:
return _create_accept_reject(base_dir, federation_list, return _create_accept_reject(base_dir, federation_list,
nickname, domain, port, nickname, domain, port,
toUrl, ccUrl, http_prefix, to_url, cc_url, http_prefix,
objectJson, 'Accept') object_json, 'Accept')
def create_reject(base_dir: str, federation_list: [], def create_reject(base_dir: str, federation_list: [],
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
toUrl: str, ccUrl: str, http_prefix: str, to_url: str, cc_url: str, http_prefix: str,
objectJson: {}) -> {}: object_json: {}) -> {}:
return _create_accept_reject(base_dir, federation_list, return _create_accept_reject(base_dir, federation_list,
nickname, domain, port, nickname, domain, port,
toUrl, ccUrl, to_url, cc_url,
http_prefix, objectJson, 'Reject') http_prefix, object_json, 'Reject')
def _accept_follow(base_dir: str, domain: str, message_json: {}, def _accept_follow(base_dir: str, domain: str, message_json: {},

View File

@ -917,7 +917,7 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
# generate instance allow list # generate instance allow list
allowed_domains = [domain_full] allowed_domains = [domain_full]
follow_files = ('following.txt', 'followers.txt') follow_files = ('following.txt', 'followers.txt')
for subdir, dirs, files in os.walk(base_dir + '/accounts'): for _, dirs, _ in os.walk(base_dir + '/accounts'):
for acct in dirs: for acct in dirs:
if not is_account_dir(acct): if not is_account_dir(acct):
continue continue
@ -995,7 +995,7 @@ def load_cw_lists(base_dir: str, verbose: bool) -> {}:
if not os.path.isdir(base_dir + '/cwlists'): if not os.path.isdir(base_dir + '/cwlists'):
return {} return {}
result = {} result = {}
for subdir, dirs, files in os.walk(base_dir + '/cwlists'): for _, _, files in os.walk(base_dir + '/cwlists'):
for fname in files: for fname in files:
if not fname.endswith('.json'): if not fname.endswith('.json'):
continue continue