pass full Response from ap_utils.activity_request, use it for Actor 404

This commit is contained in:
jesopo 2019-09-17 17:41:15 +01:00
parent ee6360be22
commit f84b48adbe
2 changed files with 15 additions and 13 deletions

View file

@ -11,10 +11,13 @@ class Actor(object):
self.outbox = None self.outbox = None
def load(self): def load(self):
data = ap_utils.activity_request(self.url) response = ap_utils.activity_request(self.url)
self.username = data["preferredUsername"] if response.code == 200:
self.inbox = Inbox(data["inbox"]) self.username = response.data["preferredUsername"]
self.outbox = Outbox(data["outbox"]) self.inbox = Inbox(response.data["inbox"])
self.outbox = Outbox(responsedata["outbox"])
return True
return False
class Outbox(object): class Outbox(object):
def __init__(self, url): def __init__(self, url):
@ -24,16 +27,16 @@ class Outbox(object):
outbox = ap_utils.activity_request(self._url) outbox = ap_utils.activity_request(self._url)
items = None items = None
if "first" in outbox: if "first" in outbox.data:
if type(outbox["first"]) == dict: if type(outbox.data["first"]) == dict:
# pleroma # pleroma
items = outbox["first"]["orderedItems"] items = outbox.data["first"]["orderedItems"]
else: else:
# mastodon # mastodon
first = ap_utils.activity_request(outbox["first"]) first = ap_utils.activity_request(outbox.data["first"])
items = first["orderedItems"] items = first["orderedItems"]
else: else:
items = outbox["orderedItems"] items = outbox.data["orderedItems"]
return items return items
class Inbox(object): class Inbox(object):
@ -53,5 +56,5 @@ class Inbox(object):
headers.append(["signature", signature]) headers.append(["signature", signature])
return ap_utils.activity_request(self._url, activity.format(sender), return ap_utils.activity_request(self._url, activity.format(sender),
method="POST", headers=dict(headers)) method="POST", headers=dict(headers)).data

View file

@ -26,7 +26,7 @@ def activity_request(url, data=None, method="GET", type=ACTIVITY_TYPE,
request = utils.http.Request(url, headers=headers, useragent=USERAGENT, request = utils.http.Request(url, headers=headers, useragent=USERAGENT,
content_type=content_type, post_data=data, method=method, json=True, content_type=content_type, post_data=data, method=method, json=True,
json_body=True) json_body=True)
return utils.http.request(request).data return utils.http.request(request)
HOSTMETA_TEMPLATE = "https://%s/.well-known/host-meta" HOSTMETA_TEMPLATE = "https://%s/.well-known/host-meta"
WEBFINGER_TEMPLATE = "https://%s/.well-known/webfinger?resource={uri}" WEBFINGER_TEMPLATE = "https://%s/.well-known/webfinger?resource={uri}"
@ -51,7 +51,7 @@ def find_actor(username, instance):
webfinger = activity_request(webfinger_url, type=JRD_TYPE) webfinger = activity_request(webfinger_url, type=JRD_TYPE)
actor_url = None actor_url = None
for link in webfinger["links"]: for link in webfinger.data["links"]:
if link["type"] == ACTIVITY_TYPE: if link["type"] == ACTIVITY_TYPE:
return link["href"] return link["href"]
@ -63,7 +63,6 @@ def format_note(actor, note):
original_tooter = ap_actor.Actor(retoot.data["attributedTo"]) original_tooter = ap_actor.Actor(retoot.data["attributedTo"])
original_tooter.load() original_tooter.load()
original_tooter = activity_request(original_tooter_url)
retooted_user = "@%s@%s" % (original_tooter.username, retoot_instance) retooted_user = "@%s@%s" % (original_tooter.username, retoot_instance)
retoot_content = utils.http.strip_html(retoot.data["content"]) retoot_content = utils.http.strip_html(retoot.data["content"])