15m44z 续:imgrepo git push 修 URL 格式 bug + App token 回退

修 ghImgRepoPushViaGit clone URL:旧版 https://{owner}:{token}@github.com/{owner}/{repo}.git (owner 重复→404),改 https://x-access-token:{token}@github.com/{owner}/{repo}.git
ghImgRepoPush:imgrepo_token 为空时回退 GitHub App installation token(App 须装到 imgrepo 仓)
This commit is contained in:
ypsdf1
2026-11-26 17:02:38 +08:00
parent 84d2132070
commit b32b6ed9ef
+16 -3
View File
@@ -666,6 +666,14 @@ function ghImgRepoPush($player, $ticketId, $title, $tmpPath, $origName) {
$owner = isset($cfg['imgrepo_owner']) ? $cfg['imgrepo_owner'] : ''; $owner = isset($cfg['imgrepo_owner']) ? $cfg['imgrepo_owner'] : '';
$branch = (isset($cfg['imgrepo_branch']) && $cfg['imgrepo_branch'] !== '') ? $cfg['imgrepo_branch'] : 'main'; $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) $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) { if ($full === '' || strpos($full, '/') === false) {
return ['ok' => false, 'url' => '', 'path' => '', 'msg' => 'imgrepo 仓库地址未配置(img.json repo.imgrepo.仓库地址)']; 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]; return ['ok' => ($code === 0), 'msg' => $msg];
}; };
$cloneUrl = ($token !== '') // ★ 15m44z 续修:URL 格式 bug —— $full 已是 owner/repo(含斜杠),不能再拼 $owner: 前缀
? ('https://' . $owner . ':' . $token . '@github.com/' . $full . '.git') // ★ PAT 拼认证 URL(img.json token) // 旧版拼出 https://owner:token@github.com/owner/repo.git(owner 重复)→ 404
: ('https://github.com/' . $full . '.git'); // 正确: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 { try {
// 1) 本地仓(首次 clone,已有则 fetch) // 1) 本地仓(首次 clone,已有则 fetch)
if (is_dir($repoDir . '/.git')) { if (is_dir($repoDir . '/.git')) {