diff --git a/activities/models/post.py b/activities/models/post.py index 78ec496..1b993a2 100644 --- a/activities/models/post.py +++ b/activities/models/post.py @@ -775,8 +775,8 @@ class Post(StatorModel): # These have no IDs, so we have to wipe them each time post.attachments.all().delete() for attachment in get_list(data, "attachment"): - if "toot:focalPoint" in attachment: - focal_x, focal_y = attachment["toot:focalPoint"]["@list"] + if "focalPoint" in attachment: + focal_x, focal_y = attachment["focalPoint"]["@list"] else: focal_x, focal_y = None, None post.attachments.create( @@ -785,7 +785,7 @@ class Post(StatorModel): name=attachment.get("name"), width=attachment.get("width"), height=attachment.get("height"), - blurhash=attachment.get("toot:blurhash"), + blurhash=attachment.get("blurhash"), focal_x=focal_x, focal_y=focal_y, ) diff --git a/activities/views/debug.py b/activities/views/debug.py new file mode 100644 index 0000000..8e4b823 --- /dev/null +++ b/activities/views/debug.py @@ -0,0 +1,45 @@ +import pprint + +import httpx +from asgiref.sync import async_to_sync +from django import forms +from django.utils.decorators import method_decorator +from django.views.generic import FormView + +from core.ld import canonicalise +from users.decorators import admin_required +from users.models import SystemActor + + +@method_decorator(admin_required, name="dispatch") +class JsonViewer(FormView): + + template_name = "activities/debug_json.html" + + class form_class(forms.Form): + uri = forms.CharField( + help_text="The URI to fetch and show", + widget=forms.TextInput(attrs={"type": "search", "autofocus": "autofocus"}), + ) + + def form_valid(self, form): + try: + response = async_to_sync(SystemActor().signed_request)( + method="get", + uri=form.cleaned_data["uri"], + ) + except httpx.RequestError: + result = "Request Error" + else: + if response.status_code >= 400: + result = f"Error response: {response.status_code}\n{response.content}" + else: + document = canonicalise(response.json(), include_security=True) + result = pprint.pformat(document) + # Render results + context = self.get_context_data(form=form) + context["result"] = result + return self.render_to_response(context) + + +# https://pixelfed.social/p/wakest/502370273028530995 diff --git a/takahe/urls.py b/takahe/urls.py index d3572a9..9fad882 100644 --- a/takahe/urls.py +++ b/takahe/urls.py @@ -2,7 +2,7 @@ from django.conf import settings as djsettings from django.contrib import admin as djadmin from django.urls import path, re_path -from activities.views import compose, explore, follows, posts, search, timelines +from activities.views import compose, debug, explore, follows, posts, search, timelines from api.views import api_router, oauth from core import views as core from mediaproxy import views as mediaproxy @@ -17,6 +17,7 @@ urlpatterns = [ path("local/", timelines.Local.as_view(), name="local"), path("federated/", timelines.Federated.as_view(), name="federated"), path("search/", search.Search.as_view(), name="search"), + path("debug/json/", debug.JsonViewer.as_view(), name="debug_json"), path("tags//", timelines.Tag.as_view(), name="tag"), path("explore/", explore.Explore.as_view(), name="explore"), path("explore/tags/", explore.ExploreTag.as_view(), name="explore-tag"), diff --git a/templates/activities/debug_json.html b/templates/activities/debug_json.html new file mode 100644 index 0000000..d5c6e07 --- /dev/null +++ b/templates/activities/debug_json.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} + +{% block title %}Debug JSON{% endblock %} + +{% block body_class %}no-sidebar{% endblock %} + +{% block content %} +
+ {% csrf_token %} +
+ {% include "forms/_field.html" with field=form.uri %} +
+
+ +
+
+ {% if result %} +
{{ result }}
+ {% endif %} +{% endblock %}