feat: podpora GTS instancí s GTS_TOKEN, přidán arch@gts.arch-linux.cz
This commit is contained in:
+1
-1
@@ -96,7 +96,7 @@ nacelnik01@mamutovo.cz,true,false,
|
||||
sledge@mastodonczech.cz,true,false,
|
||||
tensob_@mastodonczech.cz,true,false
|
||||
archos@mamutovo.cz,true,false,
|
||||
arch@arch-linux.cz,true,false,
|
||||
arch@gts.arch-linux.cz,true,false,
|
||||
electric@vaclavpasek.cz,true,false,
|
||||
adamhavelka@mastodon.prorocketeers.com,true,false,
|
||||
Kipe@mastodon.social,true,false,
|
||||
|
||||
|
+17
-2
@@ -50,9 +50,19 @@ _TOKENS = _load_tokens()
|
||||
MASTODON_TOKEN = _TOKENS.get("MASTODON_TOKEN")
|
||||
GTS_TOKEN = _TOKENS.get("GTS_TOKEN")
|
||||
|
||||
_gts_cache: dict[str, bool] = {}
|
||||
|
||||
def _is_gts(instance: str) -> bool:
|
||||
if instance in _gts_cache:
|
||||
return _gts_cache[instance]
|
||||
info = api_get(f"https://{instance}/api/v1/instance")
|
||||
version = (info or {}).get("version", "") if isinstance(info, dict) else ""
|
||||
result = "git" in version or version.startswith("0.")
|
||||
_gts_cache[instance] = result
|
||||
return result
|
||||
|
||||
def _token_for(instance: str) -> str | None:
|
||||
"""Vrátí GTS_TOKEN pro GoToSocial instance (obsahují 'gts.' v doméně), jinak MASTODON_TOKEN."""
|
||||
if GTS_TOKEN and "gts." in instance:
|
||||
if GTS_TOKEN and _is_gts(instance):
|
||||
return GTS_TOKEN
|
||||
return MASTODON_TOKEN
|
||||
|
||||
@@ -167,6 +177,11 @@ def load_manual_accounts(seen_handles=None):
|
||||
url = f"https://{instance}/api/v1/accounts/lookup?acct={urllib.parse.quote(handle_part)}"
|
||||
token = _token_for(instance)
|
||||
acc = api_get(url, token=token)
|
||||
if not acc or not isinstance(acc, dict):
|
||||
log.debug(f" {instance}: is_gts={_is_gts(instance)}, gts_token={GTS_TOKEN is not None}")
|
||||
if GTS_TOKEN and _is_gts(instance):
|
||||
log.debug(f" {handle}: zkouším GTS_TOKEN")
|
||||
acc = api_get(url, token=GTS_TOKEN)
|
||||
if not acc or not isinstance(acc, dict):
|
||||
log.warning(f" {handle}: lookup selhal")
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user