Skip to content

Commit

Permalink
refresh mastodon sites
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and alphatownsman committed Apr 6, 2024
1 parent d2d755d commit c90d2fb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions catalog/templates/_item_card.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load i18n %}
{% load duration %}
{% if allow_embed and item.get_embed_link %}
<div class="item player">
<h5>
Expand Down
45 changes: 45 additions & 0 deletions mastodon/management/commands/mastodon_sites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import pprint

from django.core.management.base import BaseCommand

from mastodon.api import create_app
from mastodon.models import MastodonApplication


class Command(BaseCommand):
help = "Manage Mastodon sites"

def add_arguments(self, parser):
# parser.add_argument("domain", type=str, help="mastodon domain")
parser.add_argument(
"--refresh",
action="store_true",
help="refresh app registration on all sites",
)

def handle(self, *args, **options):
if options["refresh"]:
for site in MastodonApplication.objects.exclude(disabled=True):
allow_multiple_redir = True
response = create_app(site.api_domain, allow_multiple_redir)
if response.status_code != 200:
self.stdout.write(
f"Error creating app on {site.api_domain}: {response.status_code}"
)
continue
try:
data = response.json()
except Exception:
self.stdout.write(
f"Error creating app on {site.api_domain}: unable to parse response"
)
continue
site.app_id = data["id"]
site.client_id = data["client_id"]
site.client_secret = data["client_secret"]
site.vapid_key = data.get("vapid_key")
site.save(
update_fields=["app_id", "client_id", "client_secret", "vapid_key"]
)
self.stdout.write(f"updated app on {site.api_domain}")
self.stdout.write(self.style.SUCCESS("Done."))

0 comments on commit c90d2fb

Please sign in to comment.