refresh mastodon sites
This commit is contained in:
parent
d2d755d7f6
commit
c90d2fbd44
2 changed files with 46 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
{% load i18n %}
|
||||
{% load duration %}
|
||||
{% if allow_embed and item.get_embed_link %}
|
||||
<div class="item player">
|
||||
<h5>
|
||||
|
|
45
mastodon/management/commands/mastodon_sites.py
Normal file
45
mastodon/management/commands/mastodon_sites.py
Normal file
|
@ -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."))
|
Loading…
Add table
Reference in a new issue