Recursively parse activities

This commit is contained in:
Mouse Reeve
2021-02-15 17:23:17 -08:00
parent fd19b55961
commit e810c2bee0
4 changed files with 24 additions and 63 deletions

View File

@ -4,7 +4,6 @@ from urllib.parse import urldefrag
from django.http import HttpResponse
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import get_object_or_404
from django.views import View
import requests
@ -26,10 +25,8 @@ class Inbox(View):
# is it valid json? does it at least vaguely resemble an activity?
try:
resp = request.body
activity_json = json.loads(resp)
activity_type = activity_json['type'] # Follow, Accept, Create, etc
except (json.decoder.JSONDecodeError, KeyError):
activity_json = json.loads(request.body)
except json.decoder.JSONDecodeError:
return HttpResponseBadRequest()
# verify the signature
@ -43,8 +40,7 @@ class Inbox(View):
# get the activity dataclass from the type field
try:
serializer = getattr(activitypub, activity_type)
serializer(**activity_json)
activitypub.parse(activity_json)
except (AttributeError, activitypub.ActivitySerializerError):
return HttpResponseNotFound()