feat: load_config() fetches from private repo with token auth
- Primary: download from unlimitedcoding-config private repo via API token - Cache: saves .patcher.config.cache.json for offline fallback - Legacy fallback: still reads local patcher.config.json if present Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -485,14 +485,56 @@ def install_cli_js(version, cli_js_path):
|
|||||||
# Settings patching
|
# Settings patching
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
CONFIG_URL = "https://git.sensey24.ru/aibot777/unlimitedcoding-config/raw/branch/main/patcher.config.json"
|
||||||
|
CONFIG_TOKEN = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
"""Load patcher.config.json from repo root."""
|
"""Load patcher.config.json from private config repo (with token auth).
|
||||||
|
|
||||||
|
Falls back to local file if network is unavailable.
|
||||||
|
"""
|
||||||
|
# 1. Try fetching from private repo
|
||||||
|
try:
|
||||||
|
import urllib.request
|
||||||
|
req = urllib.request.Request(
|
||||||
|
CONFIG_URL,
|
||||||
|
headers={"Authorization": f"token {CONFIG_TOKEN}"},
|
||||||
|
)
|
||||||
|
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||||
|
data = json.loads(resp.read().decode("utf-8"))
|
||||||
|
# Cache locally for offline use
|
||||||
|
cache_path = os.path.join(SCRIPT_DIR, ".patcher.config.cache.json")
|
||||||
|
try:
|
||||||
|
with open(cache_path, "w") as f:
|
||||||
|
json.dump(data, f, indent=2)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return data
|
||||||
|
except Exception as e:
|
||||||
|
eprint(f" {Y}Remote config fetch failed: {e}{D}")
|
||||||
|
|
||||||
|
# 2. Fallback: cached copy
|
||||||
|
cache_path = os.path.join(SCRIPT_DIR, ".patcher.config.cache.json")
|
||||||
|
if os.path.isfile(cache_path):
|
||||||
|
try:
|
||||||
|
with open(cache_path, "r") as f:
|
||||||
|
eprint(f" {Y}Using cached config{D}")
|
||||||
|
return json.load(f)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# 3. Fallback: local file (legacy, will be removed)
|
||||||
config_path = os.path.join(SCRIPT_DIR, "patcher.config.json")
|
config_path = os.path.join(SCRIPT_DIR, "patcher.config.json")
|
||||||
if not os.path.isfile(config_path):
|
if os.path.isfile(config_path):
|
||||||
eprint(f" {R}patcher.config.json not found{D}")
|
try:
|
||||||
return None
|
with open(config_path, "r") as f:
|
||||||
with open(config_path, "r") as f:
|
return json.load(f)
|
||||||
return json.load(f)
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
eprint(f" {R}patcher.config.json not found (remote or local){D}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def ensure_dir(path, uid, gid):
|
def ensure_dir(path, uid, gid):
|
||||||
|
|||||||
Reference in New Issue
Block a user