forked from doubaniux/boofilsic
-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2d755d
commit c90d2fb
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.")) |