From b32b6ed9efc331fec2fe3acb3d7ba2699c3820ae Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Thu, 26 Nov 2026 17:02:38 +0800 Subject: [PATCH] =?UTF-8?q?15m44z=20=E7=BB=AD=EF=BC=9Aimgrepo=20git=20push?= =?UTF-8?q?=20=E4=BF=AE=20URL=20=E6=A0=BC=E5=BC=8F=20bug=20+=20App=20token?= =?UTF-8?q?=20=E5=9B=9E=E9=80=80=20=E4=BF=AE=20ghImgRepoPushViaGit=20clone?= =?UTF-8?q?=20URL=EF=BC=9A=E6=97=A7=E7=89=88=20https://{owner}:{token}@git?= =?UTF-8?q?hub.com/{owner}/{repo}.git=20(owner=20=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E2=86=92404)=EF=BC=8C=E6=94=B9=20https://x-access-token:{token?= =?UTF-8?q?}@github.com/{owner}/{repo}.git=20ghImgRepoPush=EF=BC=9Aimgrepo?= =?UTF-8?q?=5Ftoken=20=E4=B8=BA=E7=A9=BA=E6=97=B6=E5=9B=9E=E9=80=80=20GitH?= =?UTF-8?q?ub=20App=20installation=20token=EF=BC=88App=20=E9=A1=BB?= =?UTF-8?q?=E8=A3=85=E5=88=B0=20imgrepo=20=E4=BB=93=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gh_api.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) 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')) {