refresh Mastodon 4.x site token if unable to verify it.
This commit is contained in:
parent
65f340ea88
commit
ea4f52dfa6
3 changed files with 38 additions and 15 deletions
|
@ -5,7 +5,7 @@ from django.utils import timezone
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
from common.models import BaseJob, JobManager
|
from common.models import BaseJob, JobManager
|
||||||
from mastodon.models import MastodonApplication, detect_server_info, verify_client
|
from mastodon.models import MastodonApplication, detect_server_info
|
||||||
|
|
||||||
|
|
||||||
@JobManager.register
|
@JobManager.register
|
||||||
|
@ -18,6 +18,7 @@ class MastodonSiteCheck(BaseJob):
|
||||||
count_checked = 0
|
count_checked = 0
|
||||||
count_unreachable = 0
|
count_unreachable = 0
|
||||||
count_disabled = 0
|
count_disabled = 0
|
||||||
|
count_refreshed = 0
|
||||||
q = Q(last_reachable_date__lte=timezone.now() - timedelta(days=1)) | Q(
|
q = Q(last_reachable_date__lte=timezone.now() - timedelta(days=1)) | Q(
|
||||||
last_reachable_date__isnull=True
|
last_reachable_date__isnull=True
|
||||||
)
|
)
|
||||||
|
@ -56,17 +57,20 @@ class MastodonSiteCheck(BaseJob):
|
||||||
"disabled",
|
"disabled",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
# try:
|
try:
|
||||||
# if not verify_client(site):
|
if (
|
||||||
# logger.error(
|
site.server_version.startswith("4.")
|
||||||
# f"Unable to verify client app for {site.api_domain}, consider deleting it."
|
and "(compatible;" not in site.server_version
|
||||||
# )
|
and not site.verify()
|
||||||
# # site.delete()
|
):
|
||||||
# except Exception as e:
|
# always verify token from Mastodon 4.x
|
||||||
# logger.error(
|
site.refresh()
|
||||||
# f"Failed to verify client app for {site.api_domain}",
|
count_refreshed += 1
|
||||||
# extra={"exception": e},
|
except Exception as e:
|
||||||
# )
|
logger.error(
|
||||||
logger.info(
|
f"Failed to verify/refresh client app for {site.api_domain}",
|
||||||
f"Mastodon Site Check finished, {count_checked} checked, {count_unreachable} unreachable, {count_disabled} disabled."
|
extra={"exception": e},
|
||||||
|
)
|
||||||
|
logger.info(
|
||||||
|
f"Mastodon Site Check finished, {count_checked} checked, {count_unreachable} unreachable, {count_disabled} disabled, {count_refreshed} refreshed."
|
||||||
)
|
)
|
||||||
|
|
|
@ -440,7 +440,7 @@ def get_toot_visibility(visibility, user) -> TootVisibilityEnum:
|
||||||
return TootVisibilityEnum.UNLISTED
|
return TootVisibilityEnum.UNLISTED
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_fediverse_application(login_domain):
|
def get_or_create_fediverse_application(login_domain: str):
|
||||||
domain = login_domain
|
domain = login_domain
|
||||||
app = MastodonApplication.objects.filter(domain_name__iexact=domain).first()
|
app = MastodonApplication.objects.filter(domain_name__iexact=domain).first()
|
||||||
if not app:
|
if not app:
|
||||||
|
@ -556,6 +556,25 @@ class MastodonApplication(models.Model):
|
||||||
if next(filter(lambda e: e["shortcode"] == "star_half", j), None):
|
if next(filter(lambda e: e["shortcode"] == "star_half", j), None):
|
||||||
self.star_mode = 1
|
self.star_mode = 1
|
||||||
|
|
||||||
|
def verify(self):
|
||||||
|
return verify_client(self)
|
||||||
|
|
||||||
|
def refresh(self):
|
||||||
|
response = create_app(self.api_domain, self.server_version)
|
||||||
|
if response.status_code != 200:
|
||||||
|
logger.error(
|
||||||
|
f"Error creating app for {self.domain_name} on {self.api_domain}: {response.status_code}"
|
||||||
|
)
|
||||||
|
return False
|
||||||
|
data = response.json()
|
||||||
|
self.app_id = data["id"]
|
||||||
|
self.client_id = data["client_id"]
|
||||||
|
self.client_secret = data["client_secret"]
|
||||||
|
self.vapid_key = data.get("vapid_key", "")
|
||||||
|
self.save()
|
||||||
|
logger.info(f"Refreshed {self.api_domain}")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Mastodon:
|
class Mastodon:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[project]
|
[project]
|
||||||
name = "neodb"
|
name = "neodb"
|
||||||
version = "0.10"
|
version = "0.11"
|
||||||
description = "🧩 self-hosted server tracking what you read/watch/listen/play, powering a global distributed community federating via ActivityPub."
|
description = "🧩 self-hosted server tracking what you read/watch/listen/play, powering a global distributed community federating via ActivityPub."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">= 3.12"
|
requires-python = ">= 3.12"
|
||||||
|
|
Loading…
Add table
Reference in a new issue