15m44w 工单附件换思路: issue API不支持附件, 改走git推图仓
- gh_api.php 新增 ghImgRepoPush/ghGitAvailable/ghImgRepoPushViaGit/ghImgRepoPushViaContents
读 img.json repo.imgrepo(模式/用户名/仓库地址/key登录密码/分支), 运行时先 ghGitAvailable
有git走 commit+push(PAT拼认证URL), 没git走 Contents API 兜底, raw链接 raw.githubusercontent.com
仓内路径 {玩家名}/{工单号}_{YYYYMMDD}_{清洗标题}/{原文件名}; 删掉 ghReadGitCredential(改读img.json token)
- lsky.php loadImgJson 解析 imgrepo 段 + imgrepo_mode/owner/full/branch/token
- api/ticket.php uploadTicketFiles 分流: imgrepo_mode=gh 存临时文件返回 @ghimgrepo: 占位,
图床模式走图床拿真URL; ticketCreate 推仓后回写 images 拿 raw URL
- api/gh_git_probe.php 新增诊断端点(检测git/imgrepo配置/raw域名可达性)
- img.json 仓库版 imgrepo 段全占位符(真PAT在 .workbuddy 不推git)
This commit is contained in:
@@ -74,6 +74,13 @@ function loadImgJson() {
|
||||
'撤销' => '已撤销',
|
||||
'处理中' => '处理中',
|
||||
],
|
||||
// ★ 15m44w: GitHub 图片仓(imgrepo)配置——附件走 git 推图仓拿 raw URL,省服务器内存
|
||||
// (用户定调:GitHub 模式本就是为省内存才做的,附件不走图床 API 而走 git 推仓)
|
||||
'imgrepo_mode' => 'gh', // 'gh'=git仓模式 | 'img'=图床模式(归一化后)
|
||||
'imgrepo_owner' => '', // 用户名(owner)
|
||||
'imgrepo_full' => '', // owner/repo(从仓库地址提取)
|
||||
'imgrepo_branch' => 'main', // 分支
|
||||
'imgrepo_token' => '', // key/登录密码(当 PAT 用)
|
||||
];
|
||||
$file = __DIR__ . '/img.json';
|
||||
if (!is_readable($file)) return $cfg;
|
||||
@@ -143,6 +150,46 @@ function loadImgJson() {
|
||||
if ($k !== '') $cfg['gh_label_map'][$k] = trim((string)$v);
|
||||
}
|
||||
}
|
||||
// ★ 15m44w: 读 repo.imgrepo(GitHub 图片仓)—— 附件走 git 推图仓拿 raw URL,省服务器内存。
|
||||
// 归一化判断 模式 字段:true / gh / GH / GitHub / github / GitHub-issue(不区分大小写)
|
||||
// → git仓模式(imgrepo_mode='gh');false / img / 图床 / tuchuang → 图床模式('img')。
|
||||
if (isset($j['repo']['imgrepo']) && is_array($j['repo']['imgrepo'])) {
|
||||
$ir = $j['repo']['imgrepo'];
|
||||
$modeRaw = $ir['模式'] ?? null;
|
||||
// 归一化:布尔 true→'gh',false→'img';字符串去空格/小写/去 -_[],
|
||||
// 含 github/gh 或等于 gh 算 git仓;含 img/图床/tuchuang/lan/lsky 算图床;缺省按 true 处理
|
||||
$modeNorm = '';
|
||||
if (is_bool($modeRaw)) {
|
||||
$modeNorm = $modeRaw ? 'gh' : 'img';
|
||||
} else {
|
||||
$modeNorm = strtolower(trim((string)$modeRaw));
|
||||
$modeNorm = str_replace([' ', '-', '_', '[', ']'], '', $modeNorm);
|
||||
}
|
||||
if ($modeNorm === 'gh' || $modeNorm === 'github' || strpos($modeNorm, 'github') === 0 || $modeNorm === 'true') {
|
||||
$cfg['imgrepo_mode'] = 'gh';
|
||||
} elseif ($modeNorm === 'img' || $modeNorm === '图床' || $modeNorm === 'tuchuang' || $modeNorm === 'lan' || $modeNorm === 'lsky' || $modeNorm === 'false' || $modeNorm === '') {
|
||||
$cfg['imgrepo_mode'] = 'img';
|
||||
} else {
|
||||
// 未知值按 git仓模式(用户填 GitHub 变体多)
|
||||
$cfg['imgrepo_mode'] = 'gh';
|
||||
}
|
||||
$cfg['imgrepo_owner'] = trim((string)($ir['用户名'] ?? ''));
|
||||
$cfg['imgrepo_token'] = trim((string)($ir['key/登录密码'] ?? ''));
|
||||
$cfg['imgrepo_branch'] = trim((string)($ir['分支'] ?? 'main'));
|
||||
if ($cfg['imgrepo_branch'] === '') $cfg['imgrepo_branch'] = 'main';
|
||||
// 仓库地址 https://github.com/owner/name[.git] → 提取 owner/name
|
||||
$irUrl = trim((string)($ir['仓库地址'] ?? ''));
|
||||
$irPath = preg_replace('#^https?://#i', '', $irUrl);
|
||||
$irPath = preg_replace('#^github\.com/#i', '', $irPath);
|
||||
$irPath = preg_replace('#\.git$#i', '', $irPath);
|
||||
$irPath = trim($irPath, '/');
|
||||
$cfg['imgrepo_full'] = (strpos($irPath, '/') !== false) ? $irPath : '';
|
||||
// 仓库地址有但 owner 没填 → 从仓库地址补 owner
|
||||
if ($cfg['imgrepo_owner'] === '' && $cfg['imgrepo_full'] !== '') {
|
||||
$parts = explode('/', $cfg['imgrepo_full']);
|
||||
$cfg['imgrepo_owner'] = $parts[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isset($j['repo']['webhook_secret'])) {
|
||||
// 兼容旧顶层 webhook_secret(已部署的生产 img.json 可能是旧结构)
|
||||
|
||||
Reference in New Issue
Block a user