15m44v: 修附件占位符替换+token验真+ghLog路径

- gh_api.php ghSyncCreate: 占位符替换串 '\U📎 附件\1\E' 改 '\u📎 附件\1'
  根因: PCRE 的 \U..\E 是大小写转换开关, 夹在 emoji 后把 CJK 误转/乱码,
  导致 issue body 里 [图片N] 未正确替换为附件提示; \u 对 CJK 恒等无副作用
  加 create 诊断日志(has_attach/desc_head/imgs)写 /plugin/gh_sync.log
- gh_api.php ghLog: 路径 dirname(__DIR__)→__DIR__
  根因: gh_api.php 在 /plugin/, __DIR__=/plugin, 旧 dirname 得到网站根 /,
  日志被写到网站根而非 /plugin → 用户在 /plugin 找永远 NOT FOUND
- gh_api.php ghApiRequest: 加 Cache-Control: no-store 头, 防 CF 边缘缓存验活响应
- gh_oauth.php: /user 验活加唯一 query 尾巴(x=nocache_<ts>rand), 破 CF 缓存,
  验活响应不可信是'没授权却显示已授权'根因; 加 probe 日志
- img.json: 修第21行混入的非法字符(反引号+中文逗号, heredoc 事故残留), 保持纯占位符
This commit is contained in:
ypsdf1
2026-11-25 15:59:07 +08:00
parent ed6462d830
commit 083f760207
2 changed files with 31 additions and 5 deletions
+20 -3
View File
@@ -39,6 +39,10 @@ function ghApiRequest($method, $path, $payload = null, $token = null) {
'Accept: application/vnd.github+json',
'X-GitHub-Api-Version: 2022-11-28',
'User-Agent: caoyuan-ticket-bot',
// ★ 15m44v: 验活/读操作禁缓存 —— 防止 Cloudflare 边缘缓存 /user 等响应导致
// token 验真误判(失效 token 被 CF 吐旧 200 缓存)。写操作(POST 建单/评论)带
// no-store 无害。
'Cache-Control: no-store',
];
if ($token !== null && $token !== '') $headers[] = 'Authorization: Bearer ' . $token;
@@ -119,19 +123,28 @@ function ghSyncCreate($ticketId, $player, $title, $description, $images = [], $t
// - @gh: 开头 = GitHub 模式占位附件(只记文件名,不走图床)→ 显示为「📎 附件:文件名」
// - http(s) = 真实图床外链 → 用 markdown 图片语法
// ★ 15m44q: 服务端把描述里的 [图片N] 占位符就地替换成「📎 附件N:文件名」。
// ★ 15m44q: 服务端把描述里的 [图片N] 占位符就地替换成「📎 附件N」。
// 占位符是前端暂存附件时插进描述的(提交后才在客户端替换),服务端拿到的 description
// 仍带着 [图片N]。旧版 ghSyncCreate 直接把原始描述塞进 issue body,导致 GitHub 上
// 显示「abc[图片1]」占位符没被替换(用户实测附件不对根因)。附件名统一在末尾集中
// 展示一次,描述里的 [图片N] 只标记"此处有附件"不重复展示文件名。
// ★ 15m44v: 替换串从 '\U📎 附件\1\E' 改为 '\u📎 附件\1'。
// 根因:PCRE 的 \U…\E 是【大小写转换开关】(\U=后续全大写,\E=恢复正常),
// 夹在 emoji 之后会把中文「附件」误转成小写/乱码;且大小写开关对 CJK 无意义。
// \u=单个字符转大写(对 CJK/emoji 恒等无副作用),\U/\E 全删,替换串干净。
$desc = (string)$description;
$hasAttach = false;
foreach ((is_array($images) ? $images : []) as $u) {
if (is_string($u)) { $hasAttach = true; break; }
}
if ($hasAttach) {
$desc = preg_replace('/\[图片(\d+)\]/u', '\U📎 附件\1\E', $desc);
$desc = preg_replace('/\[图片(\d+)\]/u', '\u📎 附件\1', $desc);
}
// ★ 15m44v: 建单诊断日志(写 /plugin/gh_sync.log),记录替换后描述 + 附件,定位占位符未替换。
ghLog('create ticket=' . $ticketId . ' has_attach=' . ($hasAttach ? 'y' : 'n')
. ' desc_len=' . mb_strlen($desc)
. ' desc_head=' . mb_substr($desc, 0, 80)
. ' imgs=' . json_encode($images, JSON_UNESCAPED_UNICODE));
$bodyParts = ['玩家:`' . $player . '`', ''];
if ($desc !== '') $bodyParts[] = $desc;
if (is_array($images) && count($images) > 0) {
@@ -414,7 +427,11 @@ function ghHandleWebhook($payload, $event) {
/** 写诊断日志(1 天自动清理) */
function ghLog($msg) {
try {
$dir = dirname(__DIR__);
// ★ 15m44v 修:日志写 __DIR__(= /plugin,gh_api.php 所在目录),与 ticket_debug.log 同目录。
// 旧版用 dirname(__DIR__):gh_api.php 在 /plugin/gh_api.php,__DIR__=/plugin,
// dirname('/') 得到网站根 /,日志被写到网站根而非 /plugin → 用户/我去 /plugin 找
// 永远 NOT FOUND(关键谜团根因)。改 __DIR__ 后落 /plugin/gh_sync.log。
$dir = __DIR__;
$file = $dir . '/gh_sync.log';
$cut = time() - 86400;
if (is_dir($dir)) {