diff --git a/gh_api.php b/gh_api.php index b15f313..0bc091a 100644 --- a/gh_api.php +++ b/gh_api.php @@ -666,6 +666,14 @@ function ghImgRepoPush($player, $ticketId, $title, $tmpPath, $origName) { $owner = isset($cfg['imgrepo_owner']) ? $cfg['imgrepo_owner'] : ''; $branch = (isset($cfg['imgrepo_branch']) && $cfg['imgrepo_branch'] !== '') ? $cfg['imgrepo_branch'] : 'main'; $token = isset($cfg['imgrepo_token']) ? $cfg['imgrepo_token'] : ''; // ★ 15m44w:账号/key 走 img.json(真值在 .workbuddy,不进 git) + // ★ 15m44z 续:imgrepo token 为空 → 回退用 GitHub App installation token(App 须装到 imgrepo 仓) + // 玩家 token 401 失效时(切匿名模式≠放弃授权,但 token 可能过期),imgrepo 附件推送也能走 App 通道。 + if ($token === '' && function_exists('ghAppInstallationToken')) { + $token = ghAppInstallationToken(); + if ($token !== '') { + ghLog('imgrepo: fallback to App installation token for imgrepo push'); + } + } if ($full === '' || strpos($full, '/') === false) { return ['ok' => false, 'url' => '', 'path' => '', 'msg' => 'imgrepo 仓库地址未配置(img.json repo.imgrepo.仓库地址)']; } @@ -744,9 +752,14 @@ function ghImgRepoPushViaGit($full, $owner, $branch, $relPath, $tmpPath, $token, return ['ok' => ($code === 0), 'msg' => $msg]; }; - $cloneUrl = ($token !== '') - ? ('https://' . $owner . ':' . $token . '@github.com/' . $full . '.git') // ★ PAT 拼认证 URL(img.json token) - : ('https://github.com/' . $full . '.git'); + // ★ 15m44z 续修:URL 格式 bug —— $full 已是 owner/repo(含斜杠),不能再拼 $owner: 前缀 + // 旧版拼出 https://owner:token@github.com/owner/repo.git(owner 重复)→ 404 + // 正确:https://x-access-token:{token}@github.com/owner/repo.git(x-access-token 是 GitHub 认证用户名) + if ($token !== '') { + $cloneUrl = 'https://x-access-token:' . $token . '@github.com/' . $full . '.git'; + } else { + $cloneUrl = 'https://github.com/' . $full . '.git'; + } try { // 1) 本地仓(首次 clone,已有则 fetch) if (is_dir($repoDir . '/.git')) {