15m44u 模式.type 归一化(gh/GH/GitHub/github 全算) + 仓库版 img.json 还原全占位符

- lsky.php loadImgJson: 模式.type 归一化判定——小写去空格/横杠/下划线后等于 gh /
  github / 以 github 开头 都算 GitHub。gh/GH/GitHub/GITHUB/github-issue/github_issue
  全部命中;其它值不算。easy/gh_enabled 改按归一化判断,不硬比 'GitHub'。
- img.json(仓库版, 进 git): api 段还原为 example.com/example 占位符(15m44t 误写真值
  进 git 已纠正), repo 段保留占位符+webhook_secret+tag。生产 img.json(FTP) 单独
  维护图床真值, 本次不部署 img.json, 避免再覆盖生产图床配置致 405。
This commit is contained in:
ypsdf1
2026-11-25 15:24:53 +08:00
parent 7ef707557d
commit ed6462d830
2 changed files with 20 additions and 11 deletions
+18 -9
View File
@@ -81,7 +81,13 @@ function loadImgJson() {
if (!is_array($j)) return $cfg;
// 模式.type
$cfg['type'] = isset($j['模式']['type']) ? trim((string)$j['模式']['type']) : '';
// ★ 15m44u 归一化:gh / GH / GitHub / github(含 github-issue 等变体)一律算 GitHub。
// 判定:去掉首尾空格 + 小写后,等于 'github' 或以 'github' 开头,或本身就是 'gh'。
$typeRaw = isset($j['模式']['type']) ? trim((string)$j['模式']['type']) : '';
$typeNorm = strtolower($typeRaw);
$typeNorm = str_replace([' ', '-', '_'], '', $typeNorm); // github-issue / github_issue → githubissue
$cfg['type'] = $typeRaw;
$isGhType = ($typeNorm === 'gh' || $typeNorm === 'github' || strpos($typeNorm, 'github') === 0);
// api.baseurl / api.key(新格式:嵌套在 api 对象下;兼容旧格式:顶层 baseurl/key)
if (isset($j['api']) && is_array($j['api'])) {
@@ -111,7 +117,8 @@ function loadImgJson() {
// - type 留空 → 内置工单 + 附件走图床(easy=true)
// - type=GitHub → 附件全走 GitHub issue,图床关闭(easy=false)
// 两者不并存:选 GitHub 后图床彻底不碰,附件由 ghSyncCreate/ghSyncReply 塞进 issue body。
$cfg['easy'] = ($cfg['type'] !== 'GitHub' && $cfg['baseurl'] !== '' && $cfg['key'] !== '' && $cfg['attach_enabled']);
// ★ 15m44u: 用归一化 $isGhType 判断(gh/GH/GitHub/github 全算),不硬比 'GitHub'。
$cfg['easy'] = (!$isGhType && $cfg['baseurl'] !== '' && $cfg['key'] !== '' && $cfg['attach_enabled']);
// GitHub issue 集成(15m44m 修正):
// webhook_secret 挪进 repo 段(用户明令:仓库 img.json 模板里 webhook_secret 塞进 repo 值,
@@ -141,10 +148,11 @@ function loadImgJson() {
// 兼容旧顶层 webhook_secret(已部署的生产 img.json 可能是旧结构)
$cfg['gh_webhook_secret'] = isset($j['webhook_secret']) ? trim((string)$j['webhook_secret']) : '';
}
// gh_enabled = 模式.type 显式填 GitHub(不再看 repo 段是否填全——模板值/占位值也算已填,
// 真正缺配置时 gh_* 为空会让 ghSyncCreate 自动跳过,不影响内置工单入库)。
// 用户手动把 模式.type 改成 GitHub 即启用 issue 同步 + 前端授权按钮。
$cfg['gh_enabled'] = ($cfg['type'] === 'GitHub');
// gh_enabled = 模式.type 归一化后算 GitHub(gh/GH/GitHub/github 全算,15m44u)。
// 不再看 repo 段是否填全——模板值/占位值也算已填,真正缺配置时 gh_* 为空会让
// ghSyncCreate 自动跳过,不影响内置工单入库。用户把 模式.type 改成任意 GitHub 写法即启用。
$cfg['gh_type'] = $isGhType;
$cfg['gh_enabled'] = $cfg['gh_type'];
return $cfg;
}
@@ -232,11 +240,12 @@ function ticketImageUpload($tmpPath, $origName) {
if ($cfg['easy']) {
return easyUploadFile($tmpPath, $origName);
}
// easy 未配置且 type 非 GitHub:兜底旧兰空图床(lsky_keys.php 还在时)
if ($cfg['type'] === '') {
// easy 未配置且非 GitHub(含 gh/GH/GitHub/github 任意写法):兜底旧兰空图床(lsky_keys.php 还在时)
if (!$cfg['gh_type'] && $cfg['type'] === '') {
return lskyUploadFile($tmpPath, $origName);
}
return ['ok' => false, 'msg' => '图床未配置:img.json 的 baseurl/key 缺失(GitHub issue 本期未启用)'];
return ['ok' => false, 'msg' => '图床未配置:img.json 的 baseurl/key 缺失(GitHub 模式附件走 issue,不走图床)'];
return ['ok' => false, 'msg' => '图床未配置:GitHub 模式附件走 issue,不走图床(loadImgJson.easy=false)'];
}
/** 加载 lsky_keys.php(只加载一次),并检查必填项 */