0) { @ob_end_clean(); } ob_start(); header('Content-Type: application/json; charset=utf-8'); header('X-Content-Type-Options: nosniff'); header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0'); require_once __DIR__ . '/../core.php'; require_once __DIR__ . '/../lsky.php'; require_once __DIR__ . '/../gh_api.php'; // 15m44v: ghApiRequest(验活 token) $cfg = loadImgJson(); $ghAuthorized = false; // ★ 15m44v: 带 token 时查该玩家是否已有【有效】GitHub token(验活,非只看存没存)。 // 前端 loadGhCfg 改成 fetch('gh_cfg.php?token=' + TOKEN) 后,据此显示「已授权」态, // 根治"重新进表单 URL 无 gh_ok 就误判为未授权"的老问题。 $probeTk = isset($_GET['token']) ? trim((string)$_GET['token']) : ''; if ($cfg['gh_enabled'] && $probeTk !== '') { $pi = validateTokenSilent($probeTk); $probePlayer = ($pi && !empty($pi['player'])) ? $pi['player'] : ''; if ($probePlayer !== '') { try { $db = getDB(); $db->exec("CREATE TABLE IF NOT EXISTS gh_auth_tokens ( player_name TEXT PRIMARY KEY, gh_login TEXT DEFAULT '', access_token TEXT NOT NULL, updated_at INTEGER NOT NULL)"); $st = $db->prepare("SELECT access_token FROM gh_auth_tokens WHERE player_name = :p AND access_token != '' ORDER BY updated_at DESC LIMIT 1"); $st->bindValue(':p', $probePlayer, SQLITE3_TEXT); $trow = $st->execute()->fetchArray(SQLITE3_ASSOC); if ($trow && !empty($trow['access_token'])) { // 验活:/user 加唯一 query 破 CF 缓存(同 gh_oauth.php 15m44v 修法) $v = ghApiRequest('GET', '/user?x=nocache_' . (int)microtime(true) . mt_rand(100000, 999999), null, $trow['access_token']); $ghAuthorized = !empty($v['ok']); } } catch (\Throwable $e) { $ghAuthorized = false; } } } success([ 'gh_enabled' => !empty($cfg['gh_enabled']), 'gh_repo' => isset($cfg['gh_repo']) ? $cfg['gh_repo'] : '', 'gh_authorized' => $ghAuthorized, ], 'ok');