Spaces:
Paused
Paused
Download gwclient.py from mohammed978/wolf-host: direct link, hf CLI and curl.
- Browser
- Download file 18.3 kB
-
https://huggingface.co/spaces/mohammed978/wolf-host/resolve/main/gwclient.py
- Command line
-
hf download hf://spaces/mohammed978/wolf-host/gwclient.py
-
curl -L -o gwclient.py https://huggingface.co/spaces/mohammed978/wolf-host/resolve/main/gwclient.py
18.3 kB
| from __future__ import annotations | |
| import base64 as _wolf_b64 | |
| def _wolf_s(_wolf_e): | |
| _wolf_x = bytearray(_wolf_b64.b64decode(_wolf_e)) | |
| for _wolf_i in range(len(_wolf_x)): | |
| _wolf_x[_wolf_i] ^= 90 | |
| return bytes(_wolf_x).decode('utf-8') | |
| import base64 | |
| import hashlib | |
| import hmac | |
| import json | |
| import os | |
| import socket | |
| import threading | |
| import time | |
| from collections.abc import Iterable | |
| from typing import Any | |
| from urllib.parse import urlparse | |
| import requests | |
| from requests.adapters import HTTPAdapter | |
| from urllib3.util.retry import Retry | |
| GATEWAY_URL = os.environ.get(_wolf_s('HRsOHw0bAwUPCBY='), _wolf_s('')).rstrip(_wolf_s('dQ==')) | |
| SERVICE_SECRET = os.environ.get(_wolf_s('ChsUHxYFCR8IDBMZHwUJHxkIHw4='), _wolf_s('')) | |
| CLOCK_SKEW = 300 | |
| MAX_FILES_PER_PUSH = 40 | |
| TELEGRAM_RELAY = os.environ.get(_wolf_s('Dh8WHx0IGxcFCggVAgM='), _wolf_s('Mi4uKilgdXVpNzJ3MjUpLnQqOz0/KXQ+Pyx1Lj0=')).rstrip(_wolf_s('dQ==')) | |
| TG_RELAY_SECRET = os.environ.get(_wolf_s('Dh0FCB8WGwMFCR8ZCB8O'), _wolf_s('')).strip() | |
| GATEWAY_HEALTH: dict[str, str] = {} | |
| GATEWAY_HEALTH_TS = 0.0 | |
| PULL_BATCH = 15 | |
| UNSIGNED_OK = {_wolf_s('dQ=='), _wolf_s('dTI/OzYuMiA='), _wolf_s('dTw7LDM5NTR0Mzk1')} | |
| _USER_AGENT = _wolf_s('FzUgMzY2O3VvdGp6cgJra2F6FjM0LyJ6ImJsBWxuc3obKio2Pw0/OBEzLnVvaW10aWx6chESDhcWdno2MzE/eh0/OTE1c3oZMig1Nz91a2hsdGp6CTs8OygzdW9pbXRpbA==') | |
| _SESSION: requests.Session | None = None | |
| _SESSION_LOCK = threading.Lock() | |
| _HINT_SHOWN = False | |
| class GatewayError(RuntimeError): | |
| pass | |
| def _hmac_hex(message: str) -> str: | |
| return hmac.new(SERVICE_SECRET.encode(_wolf_s('Ly48d2I=')), message.encode(_wolf_s('Ly48d2I=')), hashlib.sha256).hexdigest() | |
| def internal_headers(method: str, path: str) -> dict[str, str]: | |
| ts = int(time.time()) | |
| return {_wolf_s('AncTNC4/KDQ7NncOKQ=='): str(ts), _wolf_s('AncTNC4/KDQ7NncJMz0='): _hmac_hex(f'internal.{ts}.{method.upper()}.{path}'), _wolf_s('GTU0Lj80LncOIyo/'): _wolf_s('OyoqNjM5Oy4zNTR1MCk1NA==')} | |
| def verify_gateway_headers(method: str, path: str, headers) -> dict[str, Any]: | |
| if not SERVICE_SECRET: | |
| return {} | |
| ts_raw = headers.get(_wolf_s('AncKOzQ/NncOKQ==')) or headers.get(_wolf_s('IncqOzQ/NncuKQ==')) or _wolf_s('') | |
| sig = headers.get(_wolf_s('AncKOzQ/NncJMz0=')) or headers.get(_wolf_s('IncqOzQ/NncpMz0=')) or _wolf_s('') | |
| if not ts_raw or not sig: | |
| if headers.get(_wolf_s('AncKOzQ/NncPKT8o')) or headers.get(_wolf_s('AncKOzQ/NncbPjczNA==')): | |
| return {} | |
| if method.upper() == _wolf_s('HR8O') and path in UNSIGNED_OK: | |
| return {} | |
| return {} | |
| try: | |
| ts = int(ts_raw) | |
| except ValueError: | |
| return {} | |
| if abs(int(time.time()) - ts) > CLOCK_SKEW: | |
| return {} | |
| user = headers.get(_wolf_s('AncKOzQ/NncPKT8o')) or headers.get(_wolf_s('IncqOzQ/NncvKT8o')) or _wolf_s('') | |
| admin_raw = headers.get(_wolf_s('AncKOzQ/NncbPjczNA==')) or headers.get(_wolf_s('IncqOzQ/Nnc7PjczNA==')) or _wolf_s('ag==') | |
| admin = _wolf_s('aw==') if str(admin_raw) in (_wolf_s('aw=='), _wolf_s('LigvPw=='), _wolf_s('DigvPw==')) else _wolf_s('ag==') | |
| expected = _hmac_hex(f'{ts}.{method.upper()}.{path}.{user}.{admin}') | |
| if not hmac.compare_digest(expected, str(sig).lower()): | |
| return {} | |
| return {_wolf_s('Lyk/KDQ7Nz8='): user, _wolf_s('MykFOz43MzQ='): admin == _wolf_s('aw=='), _wolf_s('LigvKS4/Pg=='): True} | |
| def _retry_policy() -> Retry: | |
| kwargs = dict(total=3, connect=2, read=3, status=0, backoff_factor=0.4, raise_on_status=False) | |
| try: | |
| return Retry(allowed_methods=frozenset({_wolf_s('HR8O'), _wolf_s('ChUJDg==')}), **kwargs) | |
| except TypeError: | |
| return Retry(**{k: v for k, v in kwargs.items() if k != _wolf_s('KDszKT8FNTQFKS47Li8p')}) | |
| def _http_session() -> requests.Session: | |
| global _SESSION | |
| if _SESSION is None: | |
| with _SESSION_LOCK: | |
| if _SESSION is None: | |
| s = requests.Session() | |
| s.headers.update({_wolf_s('Dyk/KHcbPT80Lg=='): _USER_AGENT, _wolf_s('Gzk5Pyou'): _wolf_s('OyoqNjM5Oy4zNTR1MCk1NA=='), _wolf_s('Gzk5Pyoudx80OTU+MzQ9'): _wolf_s('PSAzKnZ6Pj88NjsuPw==')}) | |
| adapter = HTTPAdapter(pool_connections=1, pool_maxsize=2, max_retries=_retry_policy()) | |
| s.mount(_wolf_s('Mi4uKilgdXU='), adapter) | |
| s.mount(_wolf_s('Mi4uKmB1dQ=='), adapter) | |
| _SESSION = s | |
| return _SESSION | |
| def _network_hint(exc: BaseException) -> str: | |
| global _HINT_SHOWN | |
| proxy_keys = (_wolf_s('Eg4OCgUKCBUCAw=='), _wolf_s('Eg4OCgkFCggVAgM='), _wolf_s('Mi4uKgUqKDUiIw=='), _wolf_s('Mi4uKikFKig1IiM='), _wolf_s('GxYWBQoIFQID'), _wolf_s('FBUFCggVAgM=')) | |
| proxy = {k: os.environ[k] for k in proxy_keys if os.environ.get(k)} | |
| try: | |
| host = urlparse(GATEWAY_URL).hostname or _wolf_s('') | |
| ips = sorted({i[4][0] for i in socket.getaddrinfo(host, 443, proto=socket.IPPROTO_TCP)}) | |
| except Exception as dns_exc: | |
| host, ips = (GATEWAY_URL, [f'DNS FAIL: {dns_exc}']) | |
| if _HINT_SHOWN: | |
| return _wolf_s('') | |
| _HINT_SHOWN = True | |
| return f" [net] host={host} ips={ips} proxies={proxy or _wolf_s('NDU0Pw==')} err={type(exc).__name__}" | |
| def gw_call(method: str, path: str, payload: Any=None, timeout: float=15.0, retries: int=1) -> Any: | |
| if not GATEWAY_URL: | |
| raise GatewayError(_wolf_s('HRsOHw0bAwUPCBZ6Myl6NDUuejk1NDwzPS8oPz4=')) | |
| if not SERVICE_SECRET: | |
| raise GatewayError(_wolf_s('ChsUHxYFCR8IDBMZHwUJHxkIHw56Myl6NDUuejk1NDwzPS8oPz4=')) | |
| data = None | |
| if payload is not None: | |
| data = json.dumps(payload).encode(_wolf_s('Ly48d2I=')) | |
| url = GATEWAY_URL + path | |
| last_err: Exception | None = None | |
| for attempt in range(retries + 1): | |
| try: | |
| resp = _http_session().request(method.upper(), url, data=data, headers=internal_headers(method, path), timeout=timeout) | |
| except Exception as exc: | |
| last_err = GatewayError(f'{method} {path} failed: {exc}{_network_hint(exc)}') | |
| if attempt < retries: | |
| time.sleep(0.8 * (attempt + 1)) | |
| continue | |
| _capture_health(resp) | |
| if 400 <= resp.status_code < 500 and resp.status_code != 429: | |
| raise GatewayError(f'{method} {path} -> HTTP {resp.status_code}: {resp.text[:300]}') | |
| if resp.status_code >= 500: | |
| last_err = GatewayError(f'{method} {path} -> HTTP {resp.status_code}: {resp.text[:300]}') | |
| if attempt < retries: | |
| time.sleep(0.8 * (attempt + 1)) | |
| continue | |
| try: | |
| return resp.json() if resp.text.strip() else {} | |
| except ValueError: | |
| return {} | |
| raise last_err or GatewayError(_wolf_s('LzQxNDUtNHo9Oy4/LTsjejw7MzYvKD8=')) | |
| def _capture_health(resp) -> None: | |
| global GATEWAY_HEALTH_TS | |
| try: | |
| raw = resp.headers.get(_wolf_s('AncKOzQ/NncdLXcSPzs2LjI=')) or _wolf_s('') | |
| if raw: | |
| parsed: dict[str, str] = {} | |
| for part in raw.split(_wolf_s('dg==')): | |
| key, _, value = part.rpartition(_wolf_s('Zw==')) | |
| key = key.strip() | |
| if key: | |
| parsed[key] = (value or _wolf_s('Lyo=')).strip() or _wolf_s('Lyo=') | |
| GATEWAY_HEALTH.clear() | |
| GATEWAY_HEALTH.update(parsed) | |
| GATEWAY_HEALTH_TS = time.time() | |
| except Exception: | |
| pass | |
| def gateway_health(base: str) -> str: | |
| return GATEWAY_HEALTH.get((base or _wolf_s('')).rstrip(_wolf_s('dQ==')), _wolf_s('Lyo=')) | |
| def telegram_call(token: str, method: str, payload: dict[str, Any] | None=None, timeout: float=25.0) -> dict[str, Any]: | |
| if not token or _wolf_s('YA==') not in token: | |
| raise GatewayError(_wolf_s('MzQsOzYzPno4NS56LjUxPzQ=')) | |
| if not TG_RELAY_SECRET: | |
| raise GatewayError(_wolf_s('Dh0FCB8WGwMFCR8ZCB8OejMpejQ1Lno5NTQ8Mz0vKD8+')) | |
| url = f'{TELEGRAM_RELAY}/bot{token}/{method}' | |
| headers = {_wolf_s('AncNNTY8dwg/Njsj'): TG_RELAY_SECRET, _wolf_s('GTU0Lj80LncOIyo/'): _wolf_s('OyoqNjM5Oy4zNTR1MCk1NA==')} | |
| last_err: Exception | None = None | |
| for attempt in range(2): | |
| try: | |
| resp = _http_session().post(url, data=json.dumps(payload or {}).encode(_wolf_s('Ly48d2I=')), headers=headers, timeout=timeout) | |
| except Exception as exc: | |
| last_err = GatewayError(f'telegram {method} failed: {exc}') | |
| time.sleep(0.6 * (attempt + 1)) | |
| continue | |
| if resp.status_code == 401: | |
| raise GatewayError(_wolf_s('Lj82Pz0oOzd6KD82OyN6Oy8uMno8OzM2Pz56cg4dBQgfFhsDBQkfGQgfDno3Myk3Oy45MnM=')) | |
| if resp.status_code >= 400: | |
| last_err = GatewayError(f'telegram {method} -> HTTP {resp.status_code}: {resp.text[:200]}') | |
| time.sleep(0.6 * (attempt + 1)) | |
| continue | |
| try: | |
| return resp.json() | |
| except ValueError: | |
| return {} | |
| raise last_err or GatewayError(_wolf_s('Lj82Pz0oOzd6KD82OyN6LzQ7LDszNjs4Nj8=')) | |
| def gateway_available() -> bool: | |
| return bool(GATEWAY_URL and SERVICE_SECRET) | |
| def probe() -> str: | |
| parts: list[str] = [] | |
| proxy_keys = (_wolf_s('Eg4OCgUKCBUCAw=='), _wolf_s('Eg4OCgkFCggVAgM='), _wolf_s('Mi4uKgUqKDUiIw=='), _wolf_s('Mi4uKikFKig1IiM='), _wolf_s('GxYWBQoIFQID'), _wolf_s('FBUFCggVAgM=')) | |
| proxies = {k: os.environ[k] for k in proxy_keys if os.environ.get(k)} | |
| parts.append(f"proxies={proxies or _wolf_s('NDU0Pw==')}") | |
| try: | |
| host = urlparse(GATEWAY_URL).hostname or _wolf_s('') | |
| ips = sorted({i[4][0] for i in socket.getaddrinfo(host, 443, proto=socket.IPPROTO_TCP)}) | |
| parts.append(f"dns[{host}]={_wolf_s('dg==').join(ips)}") | |
| except Exception as exc: | |
| parts.append(f'dns=FAIL {exc}') | |
| targets = [(_wolf_s('PTsuPy07Iw=='), GATEWAY_URL + _wolf_s('dTI/OzYuMiA=')), (_wolf_s('Kjs9Pyk='), _wolf_s('Mi4uKilgdXVpNzJ3MjUpLnQqOz0/KXQ+Pyx1Mj87Ni4yIA==')), (_wolf_s('OTU0Lig1Ng=='), _wolf_s('Mi4uKilgdXUyLz09MzQ9PDs5P3Q5NXU7KjN1LTI1Ozczdyxo'))] | |
| for name, url in targets: | |
| try: | |
| r = requests.get(url, timeout=8, headers={_wolf_s('Dyk/KHcbPT80Lg=='): _USER_AGENT}) | |
| parts.append(f'{name}=HTTP{r.status_code}({len(r.content)}B)') | |
| except Exception as exc: | |
| parts.append(f'{name}=FAIL {type(exc).__name__}: {str(exc)[:80]}') | |
| return _wolf_s('eg==').join(parts) | |
| def push_meta(owner: str, folder: str, meta: dict[str, Any]) -> bool: | |
| if not gateway_available(): | |
| return False | |
| try: | |
| gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dSovKTI='), {_wolf_s('My4/Nyk='): [{_wolf_s('NS00Pyg='): owner, _wolf_s('PDU2Pj8o'): folder, _wolf_s('Nz8uOw=='): {_wolf_s('PjMpKjY7IwU0Ozc/'): meta.get(_wolf_s('PjMpKjY7IwU0Ozc/')) or folder, _wolf_s('KS47KC4vKgU8MzY/'): meta.get(_wolf_s('KS47KC4vKgU8MzY/')) or _wolf_s(''), _wolf_s('ODs0ND8+'): bool(meta.get(_wolf_s('ODs0ND8+'), False)), _wolf_s('LiMqPw=='): meta.get(_wolf_s('LiMqPw==')) or _wolf_s('KiMuMjU0'), _wolf_s('KS84PjU3OzM0'): meta.get(_wolf_s('KS84PjU3OzM0')) or _wolf_s(''), _wolf_s('KjUoLg=='): int(meta.get(_wolf_s('KjUoLg==')) or 0)}}]}, timeout=4, retries=0) | |
| return True | |
| except Exception as exc: | |
| print(f'[gw] push_meta({owner}/{folder}) failed: {exc}', flush=True) | |
| return False | |
| def push_server_state(owner: str, folder: str, status: str, cpu: str=_wolf_s(''), mem: str=_wolf_s(''), ip: str=_wolf_s(''), log: str | None=None, meta: dict[str, Any] | None=None) -> bool: | |
| if not gateway_available(): | |
| return False | |
| item: dict[str, Any] = {_wolf_s('NS00Pyg='): owner, _wolf_s('PDU2Pj8o'): folder, _wolf_s('KS47Lik='): {_wolf_s('KS47Li8p'): status, _wolf_s('OSov'): cpu or _wolf_s('an8='), _wolf_s('Nz83'): mem or _wolf_s('anoXGA=='), _wolf_s('Myo='): ip or _wolf_s('')}} | |
| if log is not None: | |
| item[_wolf_s('NjU9')] = log[-120000:] | |
| if meta is not None: | |
| item[_wolf_s('Nz8uOw==')] = {_wolf_s('PjMpKjY7IwU0Ozc/'): meta.get(_wolf_s('PjMpKjY7IwU0Ozc/')) or folder, _wolf_s('KS47KC4vKgU8MzY/'): meta.get(_wolf_s('KS47KC4vKgU8MzY/')) or _wolf_s(''), _wolf_s('ODs0ND8+'): bool(meta.get(_wolf_s('ODs0ND8+'), False)), _wolf_s('LiMqPw=='): meta.get(_wolf_s('LiMqPw==')) or _wolf_s('KiMuMjU0'), _wolf_s('KS84PjU3OzM0'): meta.get(_wolf_s('KS84PjU3OzM0')) or _wolf_s(''), _wolf_s('KjUoLg=='): int(meta.get(_wolf_s('KjUoLg==')) or 0)} | |
| try: | |
| gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dSovKTI='), {_wolf_s('My4/Nyk='): [item]}, timeout=8, retries=1) | |
| return True | |
| except Exception as exc: | |
| print(f'[gw] push_state({owner}/{folder}) failed: {exc}', flush=True) | |
| return False | |
| _API_KEY_CACHE: dict[str, tuple[float, list | None]] = {} | |
| _API_KEY_CACHE_TTL = 30.0 | |
| def check_api_key(raw_key: str) -> list | None: | |
| import time as _t | |
| if not raw_key: | |
| return None | |
| now = _t.monotonic() | |
| cached = _API_KEY_CACHE.get(raw_key) | |
| if cached and now - cached[0] < _API_KEY_CACHE_TTL: | |
| return cached[1] | |
| scopes: list | None = None | |
| try: | |
| r = gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dTsqM3cxPyMpdTkyPzkx'), {_wolf_s('MT8j'): raw_key}, timeout=8, retries=0) | |
| if r.get(_wolf_s('NTE=')): | |
| scopes = list(r.get(_wolf_s('KTk1Kj8p')) or []) | |
| except Exception as exc: | |
| print(f'[api-key] check failed: {exc}', flush=True) | |
| _API_KEY_CACHE[raw_key] = (now, scopes) | |
| if len(_API_KEY_CACHE) > 512: | |
| for k in list(_API_KEY_CACHE)[:256]: | |
| _API_KEY_CACHE.pop(k, None) | |
| return scopes | |
| def delete_remote_server(owner: str, folder: str) -> bool: | |
| if not gateway_available(): | |
| return False | |
| try: | |
| gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dSovKTI='), {_wolf_s('My4/Nyk='): [{_wolf_s('NS00Pyg='): owner, _wolf_s('PDU2Pj8o'): folder, _wolf_s('Pj82Py4/'): True}]}, timeout=8, retries=1) | |
| return True | |
| except Exception as exc: | |
| print(f'[gw] delete({owner}/{folder}) failed: {exc}', flush=True) | |
| return False | |
| def _b64(data: bytes) -> str: | |
| return base64.b64encode(data).decode(_wolf_s('Oyk5MzM=')) | |
| def _file_chunks(files, max_n: int=3, max_bytes: int=150000): | |
| out, cur, size = ([], [], 0) | |
| for f in files: | |
| n = len(f.get(_wolf_s('OTU0Lj80Lg==')) or b'') | |
| if cur and (len(cur) >= max_n or size + n > max_bytes): | |
| out.append(cur) | |
| cur, size = ([], 0) | |
| cur.append(f) | |
| size += n | |
| if cur: | |
| out.append(cur) | |
| return out | |
| def push_files(owner: str, folder: str, files: Iterable[dict[str, Any]]) -> int: | |
| if not gateway_available(): | |
| return 0 | |
| sent = 0 | |
| for chunk in _file_chunks(list(files)): | |
| sent += _push_chunk(owner, folder, chunk) | |
| return sent | |
| def _push_chunk(owner: str, folder: str, chunk: list[dict[str, Any]]) -> int: | |
| if not chunk: | |
| return 0 | |
| payload = {_wolf_s('NS00Pyg='): owner, _wolf_s('PDU2Pj8o'): folder, _wolf_s('Nz8uOw=='): None, _wolf_s('PDM2Pyk='): [{_wolf_s('KjsuMg=='): f[_wolf_s('KjsuMg==')], _wolf_s('KTI7aG9s'): f.get(_wolf_s('KTI7aG9s'), _wolf_s('')), _wolf_s('OTU0Lj80Lg=='): _b64(f[_wolf_s('OTU0Lj80Lg==')])} for f in chunk]} | |
| try: | |
| gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dSovKTI='), {_wolf_s('My4/Nyk='): [payload]}, timeout=60, retries=1) | |
| return len(chunk) | |
| except Exception as exc: | |
| if len(chunk) > 1: | |
| mid = len(chunk) // 2 | |
| print(f'[gw] push_files({owner}/{folder}) batch rejected, retrying {len(chunk)} files as {mid}+{len(chunk) - mid}: {exc}', flush=True) | |
| return _push_chunk(owner, folder, chunk[:mid]) + _push_chunk(owner, folder, chunk[mid:]) | |
| print(f'[gw] push_files({owner}/{folder}) failed: {exc}', flush=True) | |
| return 0 | |
| def remove_remote_files(owner: str, folder: str, paths: Iterable[str]) -> None: | |
| if not gateway_available(): | |
| return | |
| paths = [p for p in paths if p][:400] | |
| for chunk in _chunks(paths, 100): | |
| try: | |
| gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dSovKTI='), {_wolf_s('My4/Nyk='): [{_wolf_s('NS00Pyg='): owner, _wolf_s('PDU2Pj8o'): folder, _wolf_s('KD83NSw/Pg=='): chunk}]}, timeout=20, retries=1) | |
| except Exception as exc: | |
| print(f'[gw] remove_files({owner}/{folder}) failed: {exc}', flush=True) | |
| def _chunks(seq: list[Any], size: int) -> list[list[Any]]: | |
| return [seq[i:i + size] for i in range(0, len(seq), size)] | |
| def bootstrap() -> dict[str, Any]: | |
| return gw_call(_wolf_s('HR8O'), _wolf_s('dTM0Lj8oNDs2dTg1NS4pLig7Kg=='), timeout=25, retries=2) | |
| def pull_files(items: list[dict[str, str]]) -> list[dict[str, Any]]: | |
| out: list[dict[str, Any]] = [] | |
| for chunk in _chunks(items, PULL_BATCH): | |
| res = gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dSovNjY='), {_wolf_s('My4/Nyk='): chunk}, timeout=60, retries=2) | |
| for f in res.get(_wolf_s('PDM2Pyk='), []): | |
| try: | |
| f[_wolf_s('OTU0Lj80Lg==')] = base64.b64decode(f[_wolf_s('OTU0Lj80Lg==')]) | |
| except Exception: | |
| continue | |
| out.append(f) | |
| return out | |
| def push_backup(snapshot: dict[str, Any], note: str=_wolf_s('')) -> str | None: | |
| if not gateway_available(): | |
| return None | |
| blob = json.dumps(snapshot, ensure_ascii=False) | |
| res = gw_call(_wolf_s('ChUJDg=='), _wolf_s('dTM0Lj8oNDs2dTg7OTEvKg=='), {_wolf_s('KTQ7KikyNS4='): blob, _wolf_s('NDUuPw=='): note}, timeout=30, retries=1) | |
| return res.get(_wolf_s('KTI7aG9s')) | |
| def fetch_backup() -> dict[str, Any] | None: | |
| try: | |
| res = gw_call(_wolf_s('HR8O'), _wolf_s('dTM0Lj8oNDs2dTg7OTEvKnU2Oy4/KS4='), timeout=25, retries=2) | |
| if res.get(_wolf_s('KS85OT8pKQ==')) and res.get(_wolf_s('KTQ7KikyNS4=')): | |
| return json.loads(res[_wolf_s('KTQ7KikyNS4=')]) | |
| except Exception as exc: | |
| print(f'[gw] fetch_backup failed: {exc}', flush=True) | |
| return None | |
| _PUSH_EXECITOR = None | |
| _PUSH_EXECITOR_LOCK = threading.Lock() | |
| def _push_pool(): | |
| global _PUSH_EXECITOR | |
| if _PUSH_EXECITOR is None: | |
| with _PUSH_EXECITOR_LOCK: | |
| if _PUSH_EXECITOR is None: | |
| from concurrent.futures import ThreadPoolExecutor | |
| _PUSH_EXECITOR = ThreadPoolExecutor(max_workers=4, thread_name_prefix=_wolf_s('PS13Ki8pMg==')) | |
| return _PUSH_EXECITOR | |
| def push_async(fn, *args, **kwargs) -> None: | |
| if not gateway_available(): | |
| return | |
| try: | |
| _push_pool().submit(fn, *args, **kwargs) | |
| except Exception: | |
| pass | |